groovy
  1. groovy
  2. GROOVY-5427

Add consumeProcessOutputStream() and consumeProcessErrorStream()

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Process has a method named consumeProcessOutput() which consumes output and error streams together but there are no methods to consume them together. In writing a script I need the output stream but want to ignore the error stream. I propose that two new methods are added: consumeProcessOutputStream() and consumeProcessErrorStream(). There are already methods with these names just none without parameters.

        Activity

        Hide
        Paul King added a comment -

        These are easy enough to add I guess but you can just call them with null to achieve the same thing. So normally you would do:

        def stdout = new StringBuilder() // or other options
        def proc = ...
        proc.waitForProcessOutput(stdout, null)
        

        Using the waitFor variant does more resource cleanup for you.

        Show
        Paul King added a comment - These are easy enough to add I guess but you can just call them with null to achieve the same thing. So normally you would do: def stdout = new StringBuilder() // or other options def proc = ... proc.waitForProcessOutput(stdout, null ) Using the waitFor variant does more resource cleanup for you.
        Hide
        Uri Moszkowicz added a comment -

        I haven't tested that to see if it works but the API doesn't indicate that they can be null. I would have assumed that either it would crash or the stream wouldn't be read properly. Updating the documentation could be another option but as I pointed out the interface is inconsistent here.

        Show
        Uri Moszkowicz added a comment - I haven't tested that to see if it works but the API doesn't indicate that they can be null. I would have assumed that either it would crash or the stream wouldn't be read properly. Updating the documentation could be another option but as I pointed out the interface is inconsistent here.
        Hide
        Paul King added a comment - - edited

        I agree that we can make this more consistent. We should probably add the methods as you suggest:

        consumeProcessOutputStream()
        consumeProcessErrorStream()
        waitForProcessOutputStream()
        waitForProcessErrorStream()
        

        but I am wondering whether we should take Groovy 2.0 as an opportunity to rename some of the existing methods:
        consumeStreams instead of consumeProcessOutput and similarly waitForStreams or waitConsumingStreams instead of waitForProcessOutput. In which case I would remove "Process" from the name of the methods you are suggesting too. We would leave the old names around as aliases for a version or two.

        Show
        Paul King added a comment - - edited I agree that we can make this more consistent. We should probably add the methods as you suggest: consumeProcessOutputStream() consumeProcessErrorStream() waitForProcessOutputStream() waitForProcessErrorStream() but I am wondering whether we should take Groovy 2.0 as an opportunity to rename some of the existing methods: consumeStreams instead of consumeProcessOutput and similarly waitForStreams or waitConsumingStreams instead of waitForProcessOutput . In which case I would remove "Process" from the name of the methods you are suggesting too. We would leave the old names around as aliases for a version or two.
        Hide
        Uri Moszkowicz added a comment -

        I agree. I thought about opening a ticket for that but wasn't familiar with the history. I always have to re-read waitForProcessOutput() to confirm that it isn't doing what it implies - waiting until there's output and then stopping.

        Show
        Uri Moszkowicz added a comment - I agree. I thought about opening a ticket for that but wasn't familiar with the history. I always have to re-read waitForProcessOutput() to confirm that it isn't doing what it implies - waiting until there's output and then stopping.

          People

          • Assignee:
            Unassigned
            Reporter:
            Uri Moszkowicz
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: