Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用以下命令调用外部 exe:
String bat_file = "cmd /c start out.bat"; Process p= Runtime.getRuntime().exec(bat_file);
问题是我需要多次调用特定的exe,但一个接一个(下一个exe在前一个exe完成后开始)。它们不能同时运行,因为它们访问相同的文件。
我尝试使用 for 但不工作。有任何想法吗?
您的方法中的问题基本上是启动命令。它创建了一个单独的过程。如果将其删除,则可以成功使用waitFor:
String batchFile = "cmd /c out.bat"; Process p = Runtime.getRuntime().exec(batchFile); int resultCode = p.waitFor();
谢谢你。我终于解决了
String batchFile = "cmd /c start/wait out.bat";