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

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

内容简介:翻译自: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


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

查看所有标签

猜你喜欢:

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

The Ruby Programming Language

The Ruby Programming Language

David Flanagan、Yukihiro Matsumoto / O'Reilly Media, Inc. / 2008 / USD 39.99

Ruby has gained some attention through the popular Ruby on Rails web development framework, but the language alone is worthy of more consideration -- a lot more. This book offers a definition explanat......一起来看看 《The Ruby Programming Language》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具