Main.say("Installing...");
Process p1 = Runtime.getRuntime().exec(dir + "setup.exe /SILENT");
//Wait here, I need to finish installing first!
Main.say("Registering...");
Process p2 = Runtime.getRuntime().exec(installDir + "program.exe /register aaaa-bbbb-cccc");
Main.say("Updating...");
Process p4 = Runtime.getRuntime().exec(installDir + "program.exe /update -silent");
Process#waitFor()
.它的Javadoc说:
Causes the current thread to wait, if necessary, until the process represented by this Process
object has terminated.
额外:您获得子流程的退出值.因此,您可以检查代码是否已成功退出,或者是否发生错误(非零退出代码).
翻译自:https://stackoverflow.com/questions/17972380/wait-for-process-to-finish-before-proceeding-in-java