Package: org.codehaus.groovy.runtime

## [Java] Class ProcessGroovyMethods

- org.codehaus.groovy.runtime.ProcessGroovyMethods

-     public class ProcessGroovyMethods
      extends DefaultGroovyMethodsSupport

  This class defines new groovy methods which appear on normal JDK classes related to process management.

  Static methods are used with the first parameter being the destination class, i.e. `public static String reverse(String self)` provides a `reverse()` method for `String`.

  NOTE: While this class contains many 'public' static methods, it is primarily regarded as an internal class (its internal package name suggests this also). We value backwards compatibility of these methods when used within Groovy but value less backwards compatibility at the Java method call level. I.e. future versions of Groovy may remove or move a method call in this file but would normally aim to keep the method available from within Groovy.

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `protected static class` | `ProcessGroovyMethods.ProcessRunner` | A Runnable which waits for a process to complete together with a notification scheme allowing another thread to wait a maximum number of seconds for the process to complete before killing it.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static void` | `closeStreams(Process self)` Closes all the streams associated with the process (ignoring any IOExceptions).
    `` | `public static Thread` | `consumeProcessErrorStream(Process self, OutputStream err)` Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer.
    `` | `public static Thread` | `consumeProcessErrorStream(Process self, Appendable error)` Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer.
    `` | `public static void` | `consumeProcessOutput(Process self)` Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer.
    `` | `public static void` | `consumeProcessOutput(Process self, 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.
    `` | `public static void` | `consumeProcessOutput(Process self, OutputStream output, OutputStream 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.
    `` | `public static Thread` | `consumeProcessOutputStream(Process self, Appendable output)` Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer.
    `` | `public static Thread` | `consumeProcessOutputStream(Process self, OutputStream output)` Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer.
    `` | `public static Process` | `execute(String self)` Executes the command specified by `self` as a command-line process.
    `` | `public static Process` | `execute(String self, String[] envp, File dir)` Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.
    `` | `public static Process` | `execute(String self, List envp, File dir)` Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.
    `` | `public static Process` | `execute(String[] commandArray)` Executes the command specified by the given `String` array.
    `` | `public static Process` | `execute(String[] commandArray, String[] envp, File dir)` Executes the command specified by the `String` array given in the first parameter, with the environment defined by `envp` and under the working directory `dir`.
    `` | `public static Process` | `execute(String[] commandArray, List envp, File dir)` Executes the command specified by the `String` array given in the first parameter, with the environment defined by `envp` and under the working directory `dir`.
    `` | `public static Process` | `execute(List commands)` Executes the command specified by the given list.
    `` | `public static Process` | `execute(List commands, String[] envp, File dir)` Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`.
    `` | `public static Process` | `execute(List commands, List envp, File dir)` Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`.
    `` | `public static Process` | `execute(String self, Map<String, Object> options)` Executes the command specified by `self` with options provided as named parameters.
    `` | `public static Process` | `execute(String[] commandArray, Map<String, Object> options)` Executes the command specified by the given `String` array with options provided as named parameters.
    `` | `public static Process` | `execute(List commands, Map<String, Object> options)` Executes the command specified by the given list with options provided as named parameters.
    `` | `public static InputStream` | `getErr(Process self)` An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion.
    `` | `public static InputStream` | `getIn(Process self)` An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion.
    `` | `public static OutputStream` | `getOut(Process self)` An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion.
    `` | `public static String` | `getText(Process self)` Read the text of the output stream of the Process.
    `` | `public static Writer` | `leftShift(Process self, Object value)` Overloads the left shift operator (<<) to provide an append mechanism to pipe data to a Process.
    `` | `public static OutputStream` | `leftShift(Process self, byte[] value)` Overloads the left shift operator to provide an append mechanism to pipe into a Process
    `` | `public static Process` | `onExit(Process self, Closure action)` Registers a closure to be called when the process terminates.
    `` | `public static Process` | `or(Process left, Process right)` Overrides the or operator to allow one Process to asynchronously pipe data to another Process.
    `` | `public static Process` | `pipeTo(Process left, Process right)` Allows one Process to asynchronously pipe data to another Process.
    `` | `public static List<Process>` | `pipeline(List<?> commands)` Creates a native OS pipeline from a list of commands, using ProcessBuilder.startPipeline.
    `` | `public static ProcessBuilder` | `toProcessBuilder(String self)` Creates a ProcessBuilder from a command line String, tokenized on whitespace.
    `` | `public static ProcessBuilder` | `toProcessBuilder(String[] commandArray)` Creates a ProcessBuilder from a command array.
    `` | `public static ProcessBuilder` | `toProcessBuilder(List commands)` Creates a ProcessBuilder from a command list.
    `` | `public static void` | `waitForOrKill(Process self, long numberOfMillis)` Wait for the process to finish during a certain amount of time, otherwise stops the process.
    `` | `public static void` | `waitForProcessOutput(Process self)` Gets the output and error streams from a process and reads them to keep the process from blocking due to a full output buffer.
    `` | `public static void` | `waitForProcessOutput(Process self, 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.
    `` | `public static void` | `waitForProcessOutput(Process self, OutputStream output, OutputStream 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.
    `` | `public static ProcessResult` | `waitForResult(Process self)` Executes the process and waits for it to complete, capturing the standard output, standard error, and exit code into a ProcessResult.
    `` | `public static ProcessResult` | `waitForResult(Process self, long timeout, TimeUnit unit)` Executes the process and waits for it to complete within the given timeout, capturing the standard output, standard error, and exit code into a ProcessResult.
    `` | `public static void` | `withOutputStream(Process self, Closure closure)` Creates a new buffered OutputStream as stdin for this process, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.
    `` | `public static void` | `withWriter(Process self, Closure closure)` Creates a new BufferedWriter as stdin for this process, passes it to the closure, and ensures the stream is flushed and closed after the closure returns.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class DefaultGroovyMethodsSupport` | `cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarQueue, createSimilarSet, normaliseIndex, sameType, sameType, subListBorders, subListBorders, subListRange, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired, writeUTF16BomIfRequired`

- - ### Method Detail

    - #### public static void closeStreams(Process self)

      Closes all the streams associated with the process (ignoring any IOExceptions).

      Parameters:
        `self` - a Process
      Since:
        2.1

    - #### public static Thread consumeProcessErrorStream(Process self, OutputStream err)

      Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer. The processed stream data is appended to the supplied OutputStream. A new Thread is started, so this method will return immediately.

      Parameters:
        `self` - a Process
        `err` - an OutputStream to capture the process stderr
      Returns:
        the Thread
      Since:
        1.5.2

    - #### public static Thread consumeProcessErrorStream(Process self, Appendable error)

      Gets the error stream from a process and reads it to keep the process from blocking due to a full buffer. The processed stream data is appended to the supplied Appendable. A new Thread is started, so this method will return immediately.

      Parameters:
        `self` - a Process
        `error` - an Appendable to capture the process stderr
      Returns:
        the Thread
      Since:
        1.7.5

    - #### public static void consumeProcessOutput(Process self)

      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, so this method will return immediately.

      Parameters:
        `self` - a Process
      Since:
        1.0

    - #### public static void consumeProcessOutput(Process self, 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().

      Parameters:
        `self` - a Process
        `output` - an Appendable to capture the process stdout
        `error` - an Appendable to capture the process stderr
      Since:
        1.7.5

    - #### public static void consumeProcessOutput(Process self, OutputStream output, OutputStream 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 OutputStream. 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().

      Parameters:
        `self` - a Process
        `output` - an OutputStream to capture the process stdout
        `error` - an OutputStream to capture the process stderr
      Since:
        1.5.2

    - #### public static Thread consumeProcessOutputStream(Process self, Appendable output)

      Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer. The processed stream data is appended to the supplied Appendable. A new Thread is started, so this method will return immediately.

      Parameters:
        `self` - a Process
        `output` - an Appendable to capture the process stdout
      Returns:
        the Thread
      Since:
        1.7.5

    - #### public static Thread consumeProcessOutputStream(Process self, OutputStream output)

      Gets the output stream from a process and reads it to keep the process from blocking due to a full output buffer. The processed stream data is appended to the supplied OutputStream. A new Thread is started, so this method will return immediately.

      Parameters:
        `self` - a Process
        `output` - an OutputStream to capture the process stdout
      Returns:
        the Thread
      Since:
        1.5.2

    - #### public static Process execute(String self)

      Executes the command specified by `self` as a command-line process.

      For more control over Process construction you can use `java.lang.ProcessBuilder` or toProcessBuilder(String).

      throws:
        IOException if an IOException occurs.
      Parameters:
        `self` - a command line String
      Returns:
        the Process which has just started for this command line representation
      Since:
        1.0

    - #### public static Process execute(String self, String[] envp, File dir)

      Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `self` - a command line String to be executed.
        `envp` - an array of Strings, each element of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public static Process execute(String self, List envp, File dir)

      Executes the command specified by `self` with environment defined by `envp` and under the working directory `dir`.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `self` - a command line String to be executed.
        `envp` - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public static Process execute(String[] commandArray)

      Executes the command specified by the given `String` array. The first item in the array is the command; the others are the parameters.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commandArray` - an array of `String` containing the command name and parameters as separate items in the array.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public static Process execute(String[] commandArray, String[] envp, File dir)

      Executes the command specified by the `String` array given in the first parameter, with the environment defined by `envp` and under the working directory `dir`. The first item in the array is the command; the others are the parameters.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commandArray` - an array of `String` containing the command name and parameters as separate items in the array.
        `envp` - an array of Strings, each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.7.1

    - #### public static Process execute(String[] commandArray, List envp, File dir)

      Executes the command specified by the `String` array given in the first parameter, with the environment defined by `envp` and under the working directory `dir`. The first item in the array is the command; the others are the parameters.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commandArray` - an array of `String` containing the command name and parameters as separate items in the array.
        `envp` - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.7.1

    - #### public static Process execute(List commands)

      Executes the command specified by the given list. The toString() method is called for each item in the list to convert into a resulting String. The first item in the list is the command the others are the parameters.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commands` - a list containing the command name and parameters as separate items in the list.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.0

    - #### public static Process execute(List commands, String[] envp, File dir)

      Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`. The first item in the list is the command; the others are the parameters. The toString() method is called on items in the list to convert them to Strings.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commands` - a List containing the command name and parameters as separate items in the list.
        `envp` - an array of Strings, each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.7.1

    - #### public static Process execute(List commands, List envp, File dir)

      Executes the command specified by the given list, with the environment defined by `envp` and under the working directory `dir`. The first item in the list is the command; the others are the parameters. The toString() method is called on items in the list to convert them to Strings.

      For more control over Process construction you can use `java.lang.ProcessBuilder`.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commands` - a List containing the command name and parameters as separate items in the list.
        `envp` - a List of Objects (converted to Strings using toString), each member of which has environment variable settings in the format name=value, or `null` if the subprocess should inherit the environment of the current process.
        `dir` - the working directory of the subprocess, or `null` if the subprocess should inherit the working directory of the current process.
      Returns:
        the Process which has just started for this command line representation.
      Since:
        1.7.1

    - #### public static Process execute(String self, @NamedParams({ @NamedParam(value = "dir"), @NamedParam(value = "env", type = Map.class), @NamedParam(value = "redirectErrorStream", type = Boolean.class), @NamedParam(value = "inheritIO", type = Boolean.class), @NamedParam(value = "outputFile"), @NamedParam(value = "errorFile"), @NamedParam(value = "inputFile"), @NamedParam(value = "appendOutput"), @NamedParam(value = "appendError") })
      Map<String, Object> options)

      Executes the command specified by `self` with options provided as named parameters. Supported options:

      - dir: (File, Path, or String) the working directory
      - env: (Map) environment variables to add (merged with inherited environment)
      - redirectErrorStream: (boolean) merge stderr into stdout
      - inheritIO: (boolean) inherit the parent process I/O streams
      - outputFile: (File, Path, or String) redirect stdout to a file
      - errorFile: (File, Path, or String) redirect stderr to a file
      - inputFile: (File, Path, or String) redirect stdin from a file
      - appendOutput: (File, Path, or String) append stdout to a file
      - appendError: (File, Path, or String) append stderr to a file

           "make test".execute(dir: new File("/project"), env: [CI: "true"])
           "cmd".execute(redirectErrorStream: true)

      throws:
        IOException if an IOException occurs.
      Parameters:
        `self` - a command line String
        `options` - a Map of options to configure the process
      Returns:
        the Process which has just started
      Since:
        6.0.0

    - #### public static Process execute(String[] commandArray, @NamedParams({ @NamedParam(value = "dir"), @NamedParam(value = "env", type = Map.class), @NamedParam(value = "redirectErrorStream", type = Boolean.class), @NamedParam(value = "inheritIO", type = Boolean.class), @NamedParam(value = "outputFile"), @NamedParam(value = "errorFile"), @NamedParam(value = "inputFile"), @NamedParam(value = "appendOutput"), @NamedParam(value = "appendError") })
      Map<String, Object> options)

      Executes the command specified by the given `String` array with options provided as named parameters.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commandArray` - an array of Strings containing the command name and parameters
        `options` - a Map of options to configure the process (see execute(String, Map))
      Returns:
        the Process which has just started
      Since:
        6.0.0
      See Also:
        execute(String, Map)

    - #### public static Process execute(List commands, @NamedParams({ @NamedParam(value = "dir"), @NamedParam(value = "env", type = Map.class), @NamedParam(value = "redirectErrorStream", type = Boolean.class), @NamedParam(value = "inheritIO", type = Boolean.class), @NamedParam(value = "outputFile"), @NamedParam(value = "errorFile"), @NamedParam(value = "inputFile"), @NamedParam(value = "appendOutput"), @NamedParam(value = "appendError") })
      Map<String, Object> options)

      Executes the command specified by the given list with options provided as named parameters.

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commands` - a list containing the command name and parameters
        `options` - a Map of options to configure the process (see execute(String, Map))
      Returns:
        the Process which has just started
      Since:
        6.0.0
      See Also:
        execute(String, Map)

    - #### public static InputStream getErr(Process self)

      An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion.

      Parameters:
        `self` - a Process instance
      Returns:
        the error InputStream for the process
      Since:
        1.0

    - #### public static InputStream getIn(Process self)

      An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion.

      Parameters:
        `self` - a Process instance
      Returns:
        the InputStream for the process
      Since:
        1.0

    - #### public static OutputStream getOut(Process self)

      An alias method so that a process appears similar to System.out, System.in, System.err; you can use process.in, process.out, process.err in a similar fashion.

      Parameters:
        `self` - a Process instance
      Returns:
        the OutputStream for the process
      Since:
        1.0

    - #### public static String getText(Process self)

      Read the text of the output stream of the Process. Closes all the streams associated with the process after retrieving the text.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `self` - a Process instance
      Returns:
        the text of the output
      Since:
        1.0

    - #### public static Writer leftShift(Process self, Object value)

      Overloads the left shift operator (<<) to provide an append mechanism to pipe data to a Process.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `self` - a Process instance
        `value` - a value to append
      Returns:
        a Writer
      Since:
        1.0

    - #### public static OutputStream leftShift(Process self, byte[] value)

      Overloads the left shift operator to provide an append mechanism to pipe into a Process

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `self` - a Process instance
        `value` - data to append
      Returns:
        an OutputStream
      Since:
        1.0

    - #### public static Process onExit(Process self, Closure action)

      Registers a closure to be called when the process terminates. Uses Process.onExit to asynchronously notify completion.

           "cmd".execute().onExit { proc ->
               println "Exited with code: ${proc.exitValue()}"
           }

      Parameters:
        `self` - a Process
        `action` - a closure to call with the completed Process
      Returns:
        the Process to allow chaining
      Since:
        6.0.0

    - #### public static Process or(Process left, Process right)

      Overrides the or operator to allow one Process to asynchronously pipe data to another Process.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `left` - a Process instance
        `right` - a Process to pipe output to
      Returns:
        the second Process to allow chaining
      Since:
        1.5.1

    - #### public static Process pipeTo(Process left, Process right)

      Allows one Process to asynchronously pipe data to another Process.

      throws:
        java.io.IOException if an IOException occurs.
      Parameters:
        `left` - a Process instance
        `right` - a Process to pipe output to
      Returns:
        the second Process to allow chaining
      Since:
        1.5.2

    - #### public static List<Process> pipeline(List<?> commands)

      Creates a native OS pipeline from a list of commands, using ProcessBuilder.startPipeline. Each element in the list can be a String (tokenized on whitespace), a List (elements converted to Strings via `toString()`), a String array, or a ProcessBuilder for full control.

           def procs = ["ps aux", "grep java", "wc -l"].pipeline()
           println procs.last().text

      throws:
        IOException if an IOException occurs.
      Parameters:
        `commands` - a list of commands, each a String, List, String[], or ProcessBuilder
      Returns:
        the list of started Process instances
      Since:
        6.0.0

    - #### public static ProcessBuilder toProcessBuilder(String self)

      Creates a ProcessBuilder from a command line String, tokenized on whitespace. This bridges Groovy's convenient string syntax with ProcessBuilder's full feature set.

           def pb = "find . -name '*.groovy'".toProcessBuilder()
           pb.directory(new File("/project"))
           pb.redirectErrorStream(true)
           def proc = pb.start()

      Parameters:
        `self` - a command line String
      Returns:
        a ProcessBuilder ready to be configured further or started
      Since:
        6.0.0

    - #### public static ProcessBuilder toProcessBuilder(String[] commandArray)

      Creates a ProcessBuilder from a command array.

      Parameters:
        `commandArray` - an array of Strings containing the command name and parameters
      Returns:
        a ProcessBuilder ready to be configured further or started
      Since:
        6.0.0

    - #### public static ProcessBuilder toProcessBuilder(List commands)

      Creates a ProcessBuilder from a command list. The toString() method is called for each item in the list to convert into a resulting String.

      Parameters:
        `commands` - a list containing the command name and parameters
      Returns:
        a ProcessBuilder ready to be configured further or started
      Since:
        6.0.0

    - #### public static void waitForOrKill(Process self, long numberOfMillis)

      Wait for the process to finish during a certain amount of time, otherwise stops the process.

      Parameters:
        `self` - a Process
        `numberOfMillis` - the number of milliseconds to wait before stopping the process
      Since:
        1.0

    - #### public static void waitForProcessOutput(Process self)

      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.

      Parameters:
        `self` - a Process
      Since:
        1.6.5

    - #### public static void waitForProcessOutput(Process self, 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.

      Parameters:
        `self` - a Process
        `output` - an Appendable to capture the process stdout
        `error` - an Appendable to capture the process stderr
      Since:
        1.7.5

    - #### public static void waitForProcessOutput(Process self, OutputStream output, OutputStream 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 OutputStream. 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.

      Parameters:
        `self` - a Process
        `output` - an OutputStream to capture the process stdout
        `error` - an OutputStream to capture the process stderr
      Since:
        1.6.5

    - #### public static ProcessResult waitForResult(Process self)

      Executes the process and waits for it to complete, capturing the standard output, standard error, and exit code into a ProcessResult.

           def result = "ls -la".execute().waitForResult()
           if (result.ok) println result.out
           else System.err.println result.err

      throws:
        InterruptedException if the current thread is interrupted.
      Parameters:
        `self` - a Process
      Returns:
        a ProcessResult containing stdout, stderr, and exit code
      Since:
        6.0.0

    - #### public static ProcessResult waitForResult(Process self, long timeout, TimeUnit unit)

      Executes the process and waits for it to complete within the given timeout, capturing the standard output, standard error, and exit code into a ProcessResult. If the process does not complete within the timeout, it is forcibly destroyed.

           def result = "cmd".execute().waitForResult(30, TimeUnit.SECONDS)

      throws:
        InterruptedException if the current thread is interrupted.
      Parameters:
        `self` - a Process
        `timeout` - the maximum time to wait
        `unit` - the time unit of the timeout argument
      Returns:
        a ProcessResult containing stdout, stderr, and exit code
      Since:
        6.0.0

    - #### public static void withOutputStream(Process self, Closure closure)

      Creates a new buffered OutputStream as stdin for this process, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. A new Thread is started, so this method will return immediately.

      Parameters:
        `self` - a Process
        `closure` - a closure
      Since:
        1.5.2

    - #### public static void withWriter(Process self, Closure closure)

      Creates a new BufferedWriter as stdin for this process, passes it to the closure, and ensures the stream is flushed and closed after the closure returns. A new Thread is started, so this method will return immediately.

      Parameters:
        `self` - a Process
        `closure` - a closure
      Since:
        1.5.2