在继续Java之前等待进程完成

栏目: Java · 发布时间: 6年前

内容简介:翻译自:https://stackoverflow.com/questions/17972380/wait-for-process-to-finish-before-proceeding-in-java
基本上,我正在制作一个小程序,它将安装一些软件,然后运行一些基本命令来准备该程序.但是,正在发生的是程序开始安装,然后立即转到以下行(注册,更新等).当然,在完全安装之前不会发生这种情况,因此我想在运行第二个进程之前找到一种等待第一个进程的方法.例如,
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


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Usability for the Web

Usability for the Web

Tom Brinck、Darren Gergle、Scott D. Wood / Morgan Kaufmann / 2001-10-15 / USD 65.95

Every stage in the design of a new web site is an opportunity to meet or miss deadlines and budgetary goals. Every stage is an opportunity to boost or undercut the site's usability. Thi......一起来看看 《Usability for the Web》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

SHA 加密
SHA 加密

SHA 加密工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具