我使用以下命令调用外部exe:
String bat_file = "cmd /c start out.bat";
Process p= Runtime.getRuntime().exec(bat_file);
问题是我需要多次调用特定的exe,但是一个接一个地调用(下一个exe在前一个exe完成后开始)。它们在访问相同文件时无法同时运行。
我尝试使用for但不起作用。 有什么想法吗?
答案 0 :(得分:1)
您的方法中的问题基本上是 start 命令。它创建了一个单独的过程。如果删除它,则可以成功使用 waitFor :
String batchFile = "cmd /c out.bat";
Process p = Runtime.getRuntime().exec(batchFile);
int resultCode = p.waitFor();
答案 1 :(得分:0)
String batchFile = "cmd /c start/wait out.bat";