commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ioannis Latousakis <latousakis.ioan...@me.com>
Subject [exec] Custom InputStream for PumpStreamHandler
Date Sun, 12 Feb 2012 00:51:35 GMT
I am trying to make a simple replicate of a terminal for a swing application.
I want to run a java class, and any of its errors or output to be displayed on a JTextPane.
The part where I am stuck is getting input from a JTextField , on a way similar to terminal(
type the command/ input hit enter ).
What I want is when pressing enter, my input is send to the process being executed.
I have tried overriding InputStream methods but it hasn't worked yet.

This is the class I want to control through my terminal .

public class NewClass {
   BufferedReader in ;
   public NewClass(){
       in = new BufferedReader(new InputStreamReader(System.in));
       run();
   }
   private void run(){
       while (true){
           System.out.println("Who are you ?");
           try {
               System.out.println("Hello "+in.readLine());
           } catch (IOException ex) {
               Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
           }
       }
   }
   public static void main(String[] args) {
       new NewClass();
   }
}

And this is how I set my custom output 

Executor ex = new DefaultExecutor();
ex.setStreamHandler(new PumpStreamHandler(out, outerr, in));

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message