Overview | Package | Class | Deprecated | Index | Help
| Groovy 1.7.6
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.runtime
[Java] Class ProcessGroovyMethods

    java.lang.Object
      org.codehaus.groovy.runtime.DefaultGroovyMethodsSupport
          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
`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.

Method Summary
`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.
`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.
`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.
`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.
`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.
`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.
`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.
`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.
`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.
`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.
`static String` | `getText(Process self)` Read the text of the output stream of the Process.
`static Writer` | `leftShift(Process self, Object value)` Overloads the left shift operator (<<) to provide an append mechanism to pipe data to a Process.
`static OutputStream` | `leftShift(Process self, byte[] value)` Overloads the left shift operator to provide an append mechanism to pipe into a Process
`static Process` | `or(Process left, Process right)` Overrides the or operator to allow one Process to asynchronously pipe data to another Process.
`static Process` | `pipeTo(Process left, Process right)` Allows one Process to asynchronously pipe data to another Process.
`static void` | `waitForOrKill(Process self, long numberOfMillis)` Wait for the process to finish during a certain amount of time, otherwise stops the process.
`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.
`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.
`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.
`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.
`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.

Methods inherited from class DefaultGroovyMethodsSupport
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders

Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Method Detail

### consumeProcessErrorStream

    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

### consumeProcessErrorStream

    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

### consumeProcessOutput

    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

### consumeProcessOutput

    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.
  Parameters:
    `self` - a Process
    `output` - an Appendable to capture the process stdout
    `error` - an Appendable to capture the process stderr
  Since:
    1.7.5

### consumeProcessOutput

    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.
  Parameters:
    `self` - a Process
    `output` - an OutputStream to capture the process stdout
    `error` - an OutputStream to capture the process stderr
  Since:
    1.5.2

### consumeProcessOutputStream

    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

### consumeProcessOutputStream

    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

### getErr

    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

### getIn

    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

### getOut

    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

### getText

    public static String getText(Process self)

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

### leftShift

    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

### leftShift

    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

### or

    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

### pipeTo

    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

### waitForOrKill

    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

### waitForProcessOutput

    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.
  Parameters:
    `self` - a Process
  Since:
    1.6.5

### waitForProcessOutput

    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.
  Parameters:
    `self` - a Process
    `output` - an Appendable to capture the process stdout
    `error` - an Appendable to capture the process stderr
  Since:
    1.7.5

### waitForProcessOutput

    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.
  Parameters:
    `self` - a Process
    `output` - an OutputStream to capture the process stdout
    `error` - an OutputStream to capture the process stderr
  Since:
    1.6.5

### withOutputStream

    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

### withWriter

    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

Copyright © 2003-2010 The Codehaus. All rights reserved.