读书人

求教Runtime.exec如何同步

发布时间: 2012-01-06 22:55:18 作者: rapoo

求教Runtime.exec怎么同步
Runtime r = Runtime.getRuntime();
Process p = r.exec( "cmd.exe /c " + " start .\\batch.bat ");
try {
p.waitFor();
System.out.println( "Run to here ");
System.out.println( "Run to here 2222222 ");
} catch (InterruptedException e) {
e.printStackTrace();
}
发现batch.bat还在跑, "Run to here "已经打出来了,
JavaDoc里说waitFor()方法会等到该子进程结束。
求教,调用外部shell时怎么同步


[解决办法]
去掉 "start "

读书人网 >J2SE开发

热点推荐