Re: How can I call another program from Java?# Java - 爪哇娇娃
i*e
1 楼
Well. I guess it should be ok to use readLine(). How about try this code?
Runtime r = Runtime.getRuntime()
try{
Process p = r.exec("ps -l");
InputStream in = p.getInputStream();
int ch;
while((ch = in.read()) != -1) System.out.print((char)ch);
in.close();
try {
p.waitFor();
}catch(InterruptedException e) { }
}catch(Exception e){}
Runtime r = Runtime.getRuntime()
try{
Process p = r.exec("ps -l");
InputStream in = p.getInputStream();
int ch;
while((ch = in.read()) != -1) System.out.print((char)ch);
in.close();
try {
p.waitFor();
}catch(InterruptedException e) { }
}catch(Exception e){}