|
发表于 2005-4-14 11:57:00
|
显示全部楼层
经过研究,正确的程序如下:
public class test{
public static void main(String args[]){
Runtime rt=Runtime.getRuntime();
String str[]={"/bin/sh","-c","sh test.sh"};
Process pcs=rt.exec(str);
BufferedReader br = new BufferedReader(new InputStreamReader(pcs.getInputStream()));
String line=new String();
while((line = br.readLine()) != null)
{
System.out.println(line);
}
try{
pcs.waitFor();
}
catch(InterruptedException e){
System.err.println("processes was interrupted");
}
br.close();
int ret=pcs.exitValue();
System.out.println(ret);
}
} |
|