public class ProcessGroovyMethods extends DefaultGroovyMethodsSupport
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.
Modifier and Type | Class and 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.
|
DefaultGroovyMethodsSupport.RangeInfo
Constructor and Description |
---|
ProcessGroovyMethods() |
Modifier and Type | Method and Description |
---|---|
static void |
closeStreams(java.lang.Process self)
Closes all the streams associated with the process (ignoring any IOExceptions).
|
static java.lang.Thread |
consumeProcessErrorStream(java.lang.Process self,
java.lang.Appendable error)
Gets the error stream from a process and reads it
to keep the process from blocking due to a full buffer.
|
static java.lang.Thread |
consumeProcessErrorStream(java.lang.Process self,
java.io.OutputStream err)
Gets the error stream from a process and reads it
to keep the process from blocking due to a full buffer.
|
static void |
consumeProcessOutput(java.lang.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(java.lang.Process self,
java.lang.Appendable output,
java.lang.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(java.lang.Process self,
java.io.OutputStream output,
java.io.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 java.lang.Thread |
consumeProcessOutputStream(java.lang.Process self,
java.lang.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 java.lang.Thread |
consumeProcessOutputStream(java.lang.Process self,
java.io.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 java.lang.Process |
execute(java.util.List commands)
Executes the command specified by the given list.
|
static java.lang.Process |
execute(java.util.List commands,
java.util.List envp,
java.io.File dir)
Executes the command specified by the given list,
with the environment defined by
envp and under the working directory dir . |
static java.lang.Process |
execute(java.util.List commands,
java.lang.String[] envp,
java.io.File dir)
Executes the command specified by the given list,
with the environment defined by
envp and under the working directory dir . |
static java.lang.Process |
execute(java.lang.String self)
Executes the command specified by
self as a command-line process. |
static java.lang.Process |
execute(java.lang.String[] commandArray)
Executes the command specified by the given
String array. |
static java.lang.Process |
execute(java.lang.String[] commandArray,
java.util.List envp,
java.io.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 . |
static java.lang.Process |
execute(java.lang.String[] commandArray,
java.lang.String[] envp,
java.io.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 . |
static java.lang.Process |
execute(java.lang.String self,
java.util.List envp,
java.io.File dir)
Executes the command specified by
self with environment defined
by envp and under the working directory dir . |
static java.lang.Process |
execute(java.lang.String self,
java.lang.String[] envp,
java.io.File dir)
Executes the command specified by
self with environment defined by envp
and under the working directory dir . |
static java.io.InputStream |
getErr(java.lang.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 java.io.InputStream |
getIn(java.lang.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 java.io.OutputStream |
getOut(java.lang.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 java.lang.String |
getText(java.lang.Process self)
Read the text of the output stream of the Process.
|
static java.io.OutputStream |
leftShift(java.lang.Process self,
byte[] value)
Overloads the left shift operator to provide an append mechanism
to pipe into a Process
|
static java.io.Writer |
leftShift(java.lang.Process self,
java.lang.Object value)
Overloads the left shift operator (<<) to provide an append mechanism
to pipe data to a Process.
|
static java.lang.Process |
or(java.lang.Process left,
java.lang.Process right)
Overrides the or operator to allow one Process to asynchronously
pipe data to another Process.
|
static java.lang.Process |
pipeTo(java.lang.Process left,
java.lang.Process right)
Allows one Process to asynchronously pipe data to another Process.
|
static void |
waitForOrKill(java.lang.Process self,
long numberOfMillis)
Wait for the process to finish during a certain amount of time, otherwise stops the process.
|
static void |
waitForProcessOutput(java.lang.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(java.lang.Process self,
java.lang.Appendable output,
java.lang.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(java.lang.Process self,
java.io.OutputStream output,
java.io.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(java.lang.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(java.lang.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.
|
cloneSimilarCollection, cloneSimilarMap, closeQuietly, closeWithWarning, createSimilarArray, createSimilarCollection, createSimilarCollection, createSimilarList, createSimilarMap, createSimilarOrDefaultCollection, createSimilarSet, normaliseIndex, sameType, subListBorders, subListBorders
public static java.io.InputStream getIn(java.lang.Process self)
self
- a Process instancepublic static java.lang.String getText(java.lang.Process self) throws java.io.IOException
self
- a Process instancejava.io.IOException
- if an IOException occurs.public static java.io.InputStream getErr(java.lang.Process self)
self
- a Process instancepublic static java.io.OutputStream getOut(java.lang.Process self)
self
- a Process instancepublic static java.io.Writer leftShift(java.lang.Process self, java.lang.Object value) throws java.io.IOException
self
- a Process instancevalue
- a value to appendjava.io.IOException
- if an IOException occurs.public static java.io.OutputStream leftShift(java.lang.Process self, byte[] value) throws java.io.IOException
self
- a Process instancevalue
- data to appendjava.io.IOException
- if an IOException occurs.public static void waitForOrKill(java.lang.Process self, long numberOfMillis)
self
- a ProcessnumberOfMillis
- the number of milliseconds to wait before stopping the processpublic static void closeStreams(java.lang.Process self)
self
- a Processpublic static void consumeProcessOutput(java.lang.Process self)
self
- a Processpublic static void consumeProcessOutput(java.lang.Process self, java.lang.Appendable output, java.lang.Appendable error)
self
- a Processoutput
- an Appendable to capture the process stdouterror
- an Appendable to capture the process stderrpublic static void consumeProcessOutput(java.lang.Process self, java.io.OutputStream output, java.io.OutputStream error)
self
- a Processoutput
- an OutputStream to capture the process stdouterror
- an OutputStream to capture the process stderrpublic static void waitForProcessOutput(java.lang.Process self)
self
- a Processpublic static void waitForProcessOutput(java.lang.Process self, java.lang.Appendable output, java.lang.Appendable error)
self
- a Processoutput
- an Appendable to capture the process stdouterror
- an Appendable to capture the process stderrpublic static void waitForProcessOutput(java.lang.Process self, java.io.OutputStream output, java.io.OutputStream error)
self
- a Processoutput
- an OutputStream to capture the process stdouterror
- an OutputStream to capture the process stderrpublic static java.lang.Thread consumeProcessErrorStream(java.lang.Process self, java.io.OutputStream err)
self
- a Processerr
- an OutputStream to capture the process stderrpublic static java.lang.Thread consumeProcessErrorStream(java.lang.Process self, java.lang.Appendable error)
self
- a Processerror
- an Appendable to capture the process stderrpublic static java.lang.Thread consumeProcessOutputStream(java.lang.Process self, java.lang.Appendable output)
self
- a Processoutput
- an Appendable to capture the process stdoutpublic static java.lang.Thread consumeProcessOutputStream(java.lang.Process self, java.io.OutputStream output)
self
- a Processoutput
- an OutputStream to capture the process stdoutpublic static void withWriter(java.lang.Process self, Closure closure)
self
- a Processclosure
- a closurepublic static void withOutputStream(java.lang.Process self, Closure closure)
self
- a Processclosure
- a closurepublic static java.lang.Process pipeTo(java.lang.Process left, java.lang.Process right) throws java.io.IOException
left
- a Process instanceright
- a Process to pipe output tojava.io.IOException
- if an IOException occurs.public static java.lang.Process or(java.lang.Process left, java.lang.Process right) throws java.io.IOException
left
- a Process instanceright
- a Process to pipe output tojava.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String self) throws java.io.IOException
self
as a command-line process.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
self
- a command line Stringjava.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String self, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
self
with environment defined by envp
and under the working directory dir
.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
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.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String self, java.util.List envp, java.io.File dir) throws java.io.IOException
self
with environment defined
by envp
and under the working directory dir
.
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
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.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String[] commandArray) throws java.io.IOException
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
(JDK 1.5+).
commandArray
- an array of String
containing the command name and
parameters as separate items in the array.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String[] commandArray, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
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
(JDK 1.5+).
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.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.lang.String[] commandArray, java.util.List envp, java.io.File dir) throws java.io.IOException
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
(JDK 1.5+).
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.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.util.List commands) throws java.io.IOException
For more control over Process construction you can use
java.lang.ProcessBuilder
(JDK 1.5+).
commands
- a list containing the command name and
parameters as separate items in the list.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.util.List commands, java.lang.String[] envp, java.io.File dir) throws java.io.IOException
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
(JDK 1.5+).
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.java.io.IOException
- if an IOException occurs.public static java.lang.Process execute(java.util.List commands, java.util.List envp, java.io.File dir) throws java.io.IOException
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
(JDK 1.5+).
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.java.io.IOException
- if an IOException occurs.