在Java中实现进程之间的等待? [英] Implement wait between processes in Java?

查看:129
本文介绍了在Java中实现进程之间的等待?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望对我的应用程序中各个过程之间的理解和实现等待过程完成"有所帮助,这些过程需要以逐步的方式进行.我的Java文件运行一个批处理文件,然后运行一个脚本.最后,我需要以连续的方式(通过命令行)运行一系列命令.我正在使用:

I would like some help understanding and implementing a 'wait until process complete' between the various processes in my application, which need to proceed in a step-wise fashion. My java file runs a batch file which then runs a script. At the conclusion of this there are series of commands that I need to run (through the command line) in a consecutive manner. I'm using:

Runtime.getRuntime().exec("cmd /c start " + command)

运行我的批处理文件和命令(不确定该信息是否相关).现在发生的事情是,在第一步(运行运行脚本的批处理文件)完成之前,我的应用程序中需要执行的第二步正在执行.在运行下一系列命令之前,我需要第一步总结.我真的希望我有道理!

to run my batch files and commands (not sure if that information is relevant). Right now what is happening is that the second step that needs to occur in my application is executing before the first step (running the batch file which runs a script) has completed. I need the first step to conclude before running the next series of commands. I really hope I'm making sense!

推荐答案

exec()返回Process的实例,可以在其上执行waitFor().

exec() returns an instance of Process, on which you can do waitFor().

请注意:我认为启动"实际上会产生一个单独的Windows进程,因此waitFor()可能会在命令完成之前返回.尝试从命令行中删除开始"吗?

Watch out though: I think "start" will actually spawn off a separate Windows process, so waitFor() may return before the command has finished. Try removing "start" from the command line?

这篇关于在Java中实现进程之间的等待?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆