【发布时间】:2014-06-26 06:44:54
【问题描述】:
Process p = Runtime.getRuntime().exec(new String[] { "C:/work/bat/ConsoleApplication1.exe" });
Thread.sleep(4000);
p.destroy();
int res = p.waitFor();
System.out.println("res" + res);
这将打印res1 并且JVM 将立即停止,但如果是这样:
Process p = Runtime.getRuntime().exec(new String[] { "C:/work/bat/exe.bat" });
这也将在大约 4s 后打印res1,但 JVM 不会一次停止。 JVM 将在更多 6s 后停止。
这是exe.bat
C:\work\bat\ConsoleApplication1.exe
这是ConsoleApplication1.exe:
int _tmain(int argc, _TCHAR* argv[])
{
int a=0;
while(a<100){
Sleep(100);
cout<<a++ <<endl;
}
return 0;
}
那么,我怎样才能停止像exe文件这样的bat文件呢?
【问题讨论】:
标签: java batch-file process exe destroy