在我的java代码中,我有以下几行
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("another program");
我的理解是这会创建一个子进程。有没有办法使用父进程执行“另一个程序”?或者告诉父进程等待执行完成后再继续的方法?
最佳答案
Is there a way to execute "another program" using the parent process?
不,需要一个单独的过程。
...or a way to tell the parent to wait until the execution is finished before continuing?
Process#waitFor
正是这样做的:
Causes the current thread to wait, if necessary, until the process represented by this
Process
object has terminated. This method returns immediately if the subprocess has already terminated. If the subprocess has not yet terminated, the calling thread will be blocked until the subprocess exits.
例如:
pr.waitFor();
关于java - 如何告诉父进程等待子进程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26103056/