Unable to capture full output from groovy execute

让人想犯罪 __ 提交于 2019-12-11 10:49:39

问题


I am trying to list the content fo an svn folder which contains about 1200 items. Along the lines in "Execute a external program within a groovy script and capture the output", I developed the following code

def svnCommand = "svn list ${repoUrl}"
def sout = new StringBuilder()
def serr = new StringBuilder()

Process sproc = svnCommand.execute()
sproc.consumeProcessOutput(sout, serr)
sproc.waitForProcessOutput()
println sout

If I am going to run this script I always get a truncated output, no matter how high I may set initial capacity. The output is evidently truncated, as shown in the following excerpt

...
SS0D76I0.cpy
SS0D76M0.cpy
SS0D76N0.cpy
SS

Any suggestion about capturing the full output of the command? The script is running on a Windows box.


回答1:


public void consumeProcessOutput(Appendable output, Appendable error) :

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()

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)

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.

so, instead of

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

call

sproc.waitForProcessOutput(sout, serr)


来源:https://stackoverflow.com/questions/50799111/unable-to-capture-full-output-from-groovy-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!