Results 1 to 3 of 3
  1. #1
    bilbodeb is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default implementing a console

    Hi all,
    I'm developing an application (within a GUI) that needs to incorporate a system console, that means the application has a text area (jtextpane, jtexteditor, whatever...) in which the user can type commands or watch the output of the different commands.
    I was trying running a proccess as follows:
    Java Code:
                    Process p=Runtime.getRuntime().exec ("cmd");
    		 //and then I catch the output
    		InputStream is = p.getInputStream();
    		InputStream iserror = p.getErrorStream();
    		//and now, the errors (if there are)
    		BufferedReader br = new BufferedReader (new InputStreamReader (is));
    		BufferedReader berr = new BufferedReader (new InputStreamReader (iserror));
                    String aux = berr.readLine();
                    while (aux != null){
    but this code is only working when I execute command that finish, if I try to execute a command that is waiting the user's answer then it doesn't work (I think readLine() never is reached).

    Can someone help me or give me any idea?
    Thanks in advance.

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    If the external process is waiting on the user, then your readLine() may be returning null, as there is nothing to return. Then your program ends.

    You need a better way of determining when the process is complete. You should also put a Thread.sleep() in your while loop. Assume it does more reads...

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    When reading/writing to process pipes, you generally need to use threads, because blocks.

Similar Threads

  1. IMplementing the DES algo
    By jkuzhuppallil in forum Advanced Java
    Replies: 3
    Last Post: 10-01-2008, 08:24 PM
  2. implementing shape
    By sidkdbl07 in forum Java 2D
    Replies: 1
    Last Post: 01-12-2008, 06:42 PM
  3. Implementing an interface
    By bugger in forum Advanced Java
    Replies: 1
    Last Post: 01-09-2008, 01:35 PM
  4. Implementing more than one interfaces
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-24-2007, 09:50 AM
  5. Implementing and Extending together
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-24-2007, 09:49 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