groovy

Process.consumeProcessXXX methods do not handle newline properly.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.5.4
  • Fix Version/s: 1.5.5, 1.6-beta-1
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

New lines are suppressed when reading the output with the consumeXXX methods. This does not happen when I use the text properties. Unfortunately the text properties cause other problems (stall) on my machine (http://jira.codehaus.org/browse/GROOVY-2305). I think suppression of the new lines is a critical bug. In my case, I use the process output for the integration tests of my build tool.

Issue Links

Activity

Hide
Paul King added a comment -

Yes, this is a bug and will be fixed for 1.5.5. A workaround is to use the outputstream version of the method instead of the stringbuffer or writer versions of the method.

Show
Paul King added a comment - Yes, this is a bug and will be fixed for 1.5.5. A workaround is to use the outputstream version of the method instead of the stringbuffer or writer versions of the method.
Hide
Hans Dockter added a comment -

Thanks Paul. The workaround is perfect. Here is the way I do it now:

StringWriter stringWriter = new StringWriter()
Process proc = command.execute()
stringWriter << proc.in
proc.waitFor()
...

This works both on Mac and Windows.

Show
Hans Dockter added a comment - Thanks Paul. The workaround is perfect. Here is the way I do it now:
StringWriter stringWriter = new StringWriter()
Process proc = command.execute()
stringWriter << proc.in
proc.waitFor()
...
This works both on Mac and Windows.
Hide
Hans Dockter added a comment -

Thanks a lot for fixing this. The workaround worked after all not that good.

I had to switch lines from:

StringWriter stringWriterOutput = new StringWriter()
StringWriter stringWriterError = new StringWriter()
Process proc = command.execute()
stringWriterError << proc.err
stringWriterOutput << proc.in
proc.waitFor()

To:

StringWriter stringWriterOutput = new StringWriter()
StringWriter stringWriterError = new StringWriter()
Process proc = command.execute()
stringWriterOutput << proc.in
stringWriterError << proc.err
proc.waitFor()

to prevent stalling under windows. I guess in case of a long error report I would still have a dead lock.

Show
Hans Dockter added a comment - Thanks a lot for fixing this. The workaround worked after all not that good. I had to switch lines from:
StringWriter stringWriterOutput = new StringWriter()
StringWriter stringWriterError = new StringWriter()
Process proc = command.execute()
stringWriterError << proc.err
stringWriterOutput << proc.in
proc.waitFor()
To:
StringWriter stringWriterOutput = new StringWriter()
StringWriter stringWriterError = new StringWriter()
Process proc = command.execute()
stringWriterOutput << proc.in
stringWriterError << proc.err
proc.waitFor()
to prevent stalling under windows. I guess in case of a long error report I would still have a dead lock.
Hide
Paul King added a comment -

I wouldn't expect the Writer version to work before this fix, just the outputStream version. Something like:

def initialSize = 4096
def outStream = new ByteArrayOutputStream(initialSize)
def errStream = new ByteArrayOutputStream(initialSize)
def proc = "ls.exe".execute()
proc.consumeProcessOutput(outStream, errStream)
proc.waitFor()
println 'out:\n' + outStream
println 'err:\n' + errStream
Show
Paul King added a comment - I wouldn't expect the Writer version to work before this fix, just the outputStream version. Something like:
def initialSize = 4096
def outStream = new ByteArrayOutputStream(initialSize)
def errStream = new ByteArrayOutputStream(initialSize)
def proc = "ls.exe".execute()
proc.consumeProcessOutput(outStream, errStream)
proc.waitFor()
println 'out:\n' + outStream
println 'err:\n' + errStream
Hide
Hans Dockter added a comment -

Thanks Paul. And you told me so in your first comment. Somehow I didn't get it.

Show
Hans Dockter added a comment - Thanks Paul. And you told me so in your first comment. Somehow I didn't get it.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: