|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.util.ExternalCommand
public class ExternalCommand
A simple wrapper for external scripts or programs. Calls an external program with arguments and environment settings as specified and returns the output of the program.
This class is thread-safe as each call to execute()
creates
another instances of the program. It uses the default
TaskRunner
. To allow efficient thread
re-use, it is highly recommended to initially
register
your interest in the default task runner and to finally
deregister when you no longer need it.
Constructor Summary | |
---|---|
ExternalCommand(String[] cmdArray)
Creates a new instance, without specifying environment parameters and working directory. |
|
ExternalCommand(String[] cmdArray,
File workDir)
Creates a new instance, without specifying environment parameters. |
|
ExternalCommand(String[] cmdArray,
String[] envparams,
File workDir)
Creates a new instance. |
Method Summary | |
---|---|
String |
execute()
Executed the external command any further arguments and without sending input and returns its output (standard out). |
String |
execute(CharSequence input)
Executed the external command without any further arguments and returns its output (standard out). |
String |
execute(String[] furtherArguments)
Executed the external command without sending input and returns its output (standard out). |
String |
execute(String[] furtherArguments,
CharSequence input)
Executed the external command and returns its output (standard out). |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ExternalCommand(String[] cmdArray) throws IllegalArgumentException
TaskRunner
for asynchronous tasks.
cmdArray
- array containing the command to call and its general
arguments, i.e. arguments that should be used used every time the
program is called
IllegalArgumentException
- if the cmdArray
is empty,
i.e. the command name is missingpublic ExternalCommand(String[] cmdArray, File workDir) throws IllegalArgumentException
TaskRunner
for asynchronous tasks.
cmdArray
- array containing the command to call and its general
arguments, i.e. arguments that should be used used every time the
program is calledworkDir
- the working directory of the process; or null
if the command should inherit the working directory of the current
process
IllegalArgumentException
- if the cmdArray
is empty,
i.e. the command name is missingpublic ExternalCommand(String[] cmdArray, String[] envparams, File workDir) throws IllegalArgumentException
TaskRunner
for
asynchronous tasks.
cmdArray
- array containing the command to call and its general
arguments, i.e. arguments that should be used used every time the
program is calledenvparams
- an array of strings, each element of which has
environment variable settings in format name=value; might be
null
or emptyworkDir
- the working directory of the process; or null
if the command should inherit the working directory of the current
process
IllegalArgumentException
- if the cmdArray
is empty,
i.e. the command name is missingMethod Detail |
---|
public String execute() throws IOException
IOException
- if an I/O error occurspublic String execute(CharSequence input) throws IOException
input
- the input to send to the command's standard input stream;
or null
if no input should be sent
IOException
- if an I/O error occurspublic String execute(String[] furtherArguments) throws IOException
furtherArguments
- an array of further arguments to use for this
single call, might be null
; appended after the
general arguments specified in the constructor
IOException
- if an I/O error occurspublic String execute(String[] furtherArguments, CharSequence input) throws IOException
furtherArguments
- an array of further arguments to use for this
single call, might be null
; appended after the
general arguments specified in the constructorinput
- the input to send to the command's standard input stream;
or null
if no input should be sent
IOException
- if an I/O error occurspublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |