且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从groovy执行中捕获完整输出

更新时间:2023-12-05 20:01:10

public void consumeProcessOutput(可附加输出,可附加错误)

获取进程的输出和错误流并读取它们以保持由于完整的输出缓冲区而阻塞的过程。处理后的流数据将附加到提供的Appendable。为此,启动了两个Thread,因此该方法将立即返回。 即使调用waitFor(),线程也不会是join()ed。要等待输出完全消耗,请调用waitForProcessOutput()。

Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. The processed stream data is appended to the supplied Appendable. For this, two Threads are started, so this method will return immediately. The threads will not be join()ed, even if waitFor() is called. To wait for the output to be fully consumed call waitForProcessOutput().

public void waitForProcessOutput()

获取进程的输出和错误流并读取它们以防止进程因完整输出缓冲区而阻塞。丢弃流数据但避免了由于完整输出缓冲而导致的阻塞。 如果您不关心标准或错误输出并且只希望进程以静默方式运行,请使用此方法 - 但请谨慎使用,因为由于流数据被丢弃,可能很难跟踪出现问题时。为此,启动了两个Thread,但是join()ed,所以我们等待。正如waitFor ...名称所暗示的那样,我们也要等到我们完成。最后,关闭输出和错误流。

Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. The stream data is thrown away but blocking due to a full output buffer is avoided. Use this method if you don't care about the standard or error output and just want the process to run silently - use carefully however, because since the stream data is thrown away, it might be difficult to track down when something goes wrong. For this, two Threads are started, but join()ed, so we wait. As implied by the waitFor... name, we also wait until we finish as well. Finally, the output and error streams are closed.

public void waitForProcessOutput(Appendable output,Appendable error)

获取进程的输出和错误流并读取它们以防止进程因完整输出缓冲区而阻塞。处理后的流数据将附加到提供的Appendable。为此,启动了两个Thread,但是join()ed,所以我们等待。正如waitFor ...名称所暗示的那样,我们也要等到我们完成。最后,输入,输出和错误流已关闭。

Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer. The processed stream data is appended to the supplied Appendable. For this, two Threads are started, but join()ed, so we wait. As implied by the waitFor... name, we also wait until we finish as well. Finally, the input, output and error streams are closed.

因此,而不是

sproc.consumeProcessOutput(sout, serr)
sproc.waitForProcessOutput()

call

sproc.waitForProcessOutput(sout, serr)