class StreamReader extends Thread {
Reader input;
int c;
char[] chars = new char[1000];
String line;
String threadName;
public StreamReader(String threadName, Reader input) {
this.input = input;
this.threadName = threadName;
}
public void run() {
try {
while ((c = input.read(chars)) != -1) {
line = new String(chars, 0, c);
System.out.print(threadName + " " + line);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
When you start the process, you can call with
Process pro1 = Runtime.getRuntime().exec(cmd, null, new File(StartInPath));
BufferedReader brErr1 = new BufferedReader(new InputStreamReader(pro1.getErrorStream()));
BufferedReader bdIn1 = new BufferedReader(new InputStreamReader(pro1.getInputStream()));
new StreamReader("[err]", brErr1).start();
new StreamReader("[out]", bdIn1).start();
Comments
Post a Comment