import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class CmdTest {
private static final long serialVersionUID = -2650474785662737262L;
public static void main(String[] args) throws Exception {
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("c://test.bat");
DealStream errStream = new DealStream(p.getErrorStream(),"Err");
DealStream outStream = new DealStream(p.getInputStream(),"Out");
new Thread(errStream).start();
new Thread(outStream).start();
int exitValue = p.waitFor();
System.out.println("exitValue -- > " + exitValue);
}
}
class DealStream implements Runnable{
private InputStream is;
private String type;
public DealStream(InputStream is,String type){
this.is = is;
this.type = type;
}
public void run(){
try{
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String temp = null;
while((temp = br.readLine()) != null){
System.out.println(type + "-->" + temp + "/n");
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
is.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}