Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default Accessing unix system using java

    I am trying to access a unix system using java .

    Main idea is to run the command in unix shell and get the output and display in a window created in java

  2. #2
    dowell's Avatar
    dowell is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default

    Is the application running from windows or from unix???

  3. #3
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    10

    Default

    It is really not clear what you are trying to do. Just run a Java application on UNIX? Do you try to run a Java application from a Telnet session? Explain better.
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    9

    Default

    Here the output of two commands are shown in JTextArea

    Java Code:
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    public class Shell {
    	private static String command = "ls -Als";
    	private static String command2 = "cat /etc/profile";
    	private String string="";
    	public static void main(String[] args) throws java.io.IOException {
    		JFrame frame=new JFrame("Output");
    		JTextArea textArea=new JTextArea();
    		textArea.setEditable(false);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.pack();
    		frame.getContentPane().add(textArea);
    		frame.setSize(500,800);
    		frame.setVisible(true);
    		try {
    	        
    	        Process child = Runtime.getRuntime().exec(command);
    	    
    	        // Get the input stream and read from it
    	        InputStream in = child.getInputStream();
    	        int c;
    	        while ((c = in.read()) != -1) {
    	            textArea.append(String.valueOf((char)c));
    	        }
    	        in.close();
    	    } catch (IOException e) {
    	    }
    try {
    	        
    	        Process child = Runtime.getRuntime().exec(command2);
    	    
    	        // Get the input stream and read from it
    	        InputStream in = child.getInputStream();
    	        int c;
    	        while ((c = in.read()) != -1) {
    	            textArea.append(String.valueOf((char)c));
    	        }
    	        in.close();
    	    } catch (IOException e) {
    	    }
    		
    
    }
    }
    Last edited by serjant; 06-19-2008 at 08:15 AM.

Similar Threads

  1. accessing command prompt using java (netbeans)...
    By kureikougaiji in forum New To Java
    Replies: 6
    Last Post: 06-27-2008, 03:01 PM
  2. how to run java app on windows in a cron like on unix
    By rockie12 in forum Advanced Java
    Replies: 7
    Last Post: 05-23-2008, 01:39 PM
  3. Filter a file in java (unix cut command equivalent)
    By marcosabel in forum New To Java
    Replies: 0
    Last Post: 02-11-2008, 08:26 PM
  4. Running java program with arguments in Unix"
    By gvi in forum Advanced Java
    Replies: 2
    Last Post: 11-08-2007, 08:01 PM
  5. Accessing client file system
    By revathi17 in forum New To Java
    Replies: 1
    Last Post: 10-17-2007, 10:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •