我有2个java进程。我想通过ProcessBuilder
从其他流程启动其中一个流程
我的问题是我只想启动另一个进程。我不想等待它的任何结果或输出
即在开始第二个过程后,这两个过程将独立运行
我怎样才能做到这一点?不在waitFor
上致电ProcessBuilder
?不消耗OutputStreams
?
注意:第二个进程不会产生输出并且“永远”运行。实际上两者都是长期运行的过程
答案 0 :(得分:0)
通过文档,您是否正在使用进程类的waitFor方法,如果是的话。然后我猜你不需要这样做。
**waitFor**
public abstract int waitFor()
throws InterruptedException
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.
Returns:
the exit value of the process. By convention, 0 indicates normal termination.
Throws:
InterruptedException - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.
答案 1 :(得分:0)
在一个单独的线程中使用ProcessBuilder运行您的进程,在该线程中读取stdout和stderr并忽略它们,让线程在进程完成时退出