[ https://issues.apache.org/jira/browse/GROOVY-7414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14530394#comment-14530394 ]
Paul King commented on GROOVY-7414: ----------------------------------- This is "as designed" behavior. The consumeProcessOutput and waitFor methods are low-level primitives if you like which have known limitations but have been left around for people wanting that low-level and for legacy reasons. The higher-level waitForProcessOutput method is the correct abstraction for most users and is the recommended one to use. Perhaps we need to stress that further in the documentation. > Process output not always consumed before waitFor() returns > ----------------------------------------------------------- > > Key: GROOVY-7414 > URL: https://issues.apache.org/jira/browse/GROOVY-7414 > Project: Groovy > Issue Type: Bug > Components: groovy-jdk > Affects Versions: 2.4.3 > Environment: Linux junk 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-2 > (2015-04-13) x86_64 GNU/Linux running in a VirtualBox VM > Reporter: Sergey Gromov > Assignee: Guillaume Laforge > > Sometimes the {{Process.consumeProcessOutput(Appendable, Appendable)}} and > {{Process.waitFor()}} combination does not work as expected. More > specifically, sometimes {{waitFor()}} returns before all input is actually > written into {{Appendable}}. > The following script reproduces the problem: > {code:title=bug.gy} > 100.times { > def out = new StringBuilder() > def err = new StringBuilder() > def p = 'echo stuff'.execute() > p.consumeProcessOutput(out, err) > p.waitFor() > def s = out.toString() > if (s != 'stuff\n') { > println 'Bug!' > println 'OUT: ' + s.inspect() > } > } > {code} > The ability to reproduce this issue seems to depend on the system > performance. E.g. I can easily reproduce it in my virtual Linux box. The > above script fails 2 or 3 times on every launch. OTOH it's quite problematic > to reproduce on my host Windows machine even though I increased the number of > tries to 1000. Nevertheless I have reproduced it on Windows, too, a couple of > times. > I think this is major because I'm not aware of any viable workaround. The > only thing that works is to sleep a bit after waitFor() which is often > unacceptable, and it's impossible to guess for how long to sleep. > Note that {{Process.consumeProcessOutput(OutputStream, OutputStream)}} > exhibits the same broken behavior. > Also note that {{Process.waitForProcessOutput(arg, arg)}} methods work > flawlessly. -- This message was sent by Atlassian JIRA (v6.3.4#6332)