org.opensolaris.opengrok.util
Class Executor

java.lang.Object
  extended by org.opensolaris.opengrok.util.Executor

public class Executor
extends java.lang.Object

Wrapper to Java Process API


Nested Class Summary
static interface Executor.StreamHandler
          You should use the StreamHandler interface if you would like to process the output from a process while it is running
 
Constructor Summary
Executor(java.util.List<java.lang.String> cmdList)
          Create a new instance of the Executor.
Executor(java.util.List<java.lang.String> cmdList, java.io.File workingDirectory)
          Create a new instance of the Executor
Executor(java.lang.String[] cmd)
          Create a new instance of the Executor.
 
Method Summary
 int exec()
          Execute the command and collect the output.
 int exec(boolean reportExceptions)
          Execute the command and collect the output
 int exec(boolean reportExceptions, Executor.StreamHandler handler)
          Execute the command and collect the output
 java.io.Reader getErrorReader()
          Get a reader to read the output the process wrote to the error stream.
 java.io.InputStream getErrorStream()
          Get an inputstreamto read the output the process wrote to the error stream.
 java.lang.String getErrorString()
          Get the output from the process written to the error stream as a string.
 java.io.Reader getOutputReader()
          Get a reader to read the output from the process
 java.io.InputStream getOutputStream()
          Get an input stream read the output from the process
 java.lang.String getOutputString()
          Get the output from the process as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Executor

public Executor(java.lang.String[] cmd)
Create a new instance of the Executor.

Parameters:
cmd - An array containing the command to execute

Executor

public Executor(java.util.List<java.lang.String> cmdList)
Create a new instance of the Executor.

Parameters:
cmdList - A list containing the command to execute

Executor

public Executor(java.util.List<java.lang.String> cmdList,
                java.io.File workingDirectory)
Create a new instance of the Executor

Parameters:
cmdList - A list containing the command to execute
workingDirectory - The directory the process should have as the working directory
Method Detail

exec

public int exec()
Execute the command and collect the output. All exceptions will be logged.

Returns:
The exit code of the process

exec

public int exec(boolean reportExceptions)
Execute the command and collect the output

Parameters:
reportExceptions - Should exceptions be added to the log or not
Returns:
The exit code of the process

exec

public int exec(boolean reportExceptions,
                Executor.StreamHandler handler)
Execute the command and collect the output

Parameters:
reportExceptions - Should exceptions be added to the log or not
handler - The handler to handle data from standard output
Returns:
The exit code of the process

getOutputString

public java.lang.String getOutputString()
Get the output from the process as a string.

Returns:
The output from the process

getOutputReader

public java.io.Reader getOutputReader()
Get a reader to read the output from the process

Returns:
A reader reading the process output

getOutputStream

public java.io.InputStream getOutputStream()
Get an input stream read the output from the process

Returns:
A reader reading the process output

getErrorString

public java.lang.String getErrorString()
Get the output from the process written to the error stream as a string.

Returns:
The error output from the process

getErrorReader

public java.io.Reader getErrorReader()
Get a reader to read the output the process wrote to the error stream.

Returns:
A reader reading the process error stream

getErrorStream

public java.io.InputStream getErrorStream()
Get an inputstreamto read the output the process wrote to the error stream.

Returns:
An inputstream for reading the process error stream