import java.io.*; import java.util.*; public class Command implements Runnable { String theCommand; //Initilize the command Command(String c){ theCommand = c; } //start up the command public void run() { try { if (theCommand.compareTo("exit") == 0) System.exit(0); // creat a process Process p = Runtime.getRuntime().exec(theCommand); // we need 2 threads to handle both standardoutput & erroroutput Thread output_thread[] = new Thread[2]; output_thread[0] = new Thread(new Output(p,p.getInputStream())); output_thread[1] = new Thread(new Output(p,p.getErrorStream())); for (int i = 0; i < 2; i ++) { output_thread[i].start(); } for (int i = 0; i < 2; i ++) { try { output_thread[i].join(); } catch (InterruptedException e){ System.err.println(e); } } } catch (IOException e) { System.out.println(theCommand+" : Command not Found."); } }// end of run(); }// end of class Command;