|
Mp3dings 20100427 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.mospace.lang.ProcessRunnable
public class ProcessRunnable
A runnable whose run method executes a system command.
The system command is either specified as a single string or as an
array of string tokens.
Runtime.exec(java.lang.String)| Nested Class Summary | |
|---|---|
protected static class |
ProcessRunnable.FileInput
Wraps a file as a ProcessRunnable.Input. |
protected static class |
ProcessRunnable.FileOutput
Wraps a file as a ProcessRunnable.Output. |
protected static interface |
ProcessRunnable.Input
A common interface for various kinds of byte sources. |
protected static interface |
ProcessRunnable.Output
A common interface for various kinds of byte sinks. |
protected static class |
ProcessRunnable.PipeThread
A thread that writes bytes from its input to its output as long as the associated ProcessRunnable is running. |
protected static class |
ProcessRunnable.StreamInput
Wraps an input stream as a ProcessRunnable.Input. |
protected static class |
ProcessRunnable.StreamOutput
Wraps an input stream as a ProcessRunnable.Input. |
| Field Summary | |
|---|---|
protected ProcessRunnable.Output |
errp
Where the error stream of this Runnable's system command will be redirected. |
protected ProcessRunnable.Input |
inpt
Where this Runnable's system command will read its standard input from. |
protected ProcessRunnable.Output |
outp
Where the output stream of this Runnable's system command will be redirected. |
| Constructor Summary | |
|---|---|
ProcessRunnable(String command)
Constructs a new ProcessRunnable whose run() method will execute
the specified command. |
|
ProcessRunnable(String[] cmdarray)
Constructs a new ProcessRunnable whose run() method will execute
the command made up of the specified tokens. |
|
| Method Summary | |
|---|---|
void |
clearInput()
Causes this process runnable to not provide any standard input to its system command. |
String |
getCommand()
Returns the command that will be executed when run() is called. |
String[] |
getCommandArray()
Returns a copy of the command line that will be executed when run() is called. |
String |
getCommandAsString()
Returns the command that will be executed when run() is called, independently of whether this command
has been specified as a single string or as an array of string tokens. |
String[] |
getEnvironment()
Returns the environment for this process runnable's system command. |
protected ExceptionHandler |
getExceptionHandler()
Returns the exception handler that deals with exceptions thrown within the run() method. |
int |
getExitStatus()
Returns the exit status of the system process that returned last. |
File |
getWorkingDirectory()
Returns the working directory for this process runnable's system command. |
boolean |
hasInput()
Returns whether this process runnable currently has a non-null input. |
boolean |
isRunning()
Returns whether this process runnable is currently running. |
void |
readInputFrom(File f)
Makes this process runnable's system command read input from the specified file. |
void |
readInputFrom(InputStream i)
Makes this process runnable's system command read input from the specified stream. |
void |
redirectErrorsTo(File f)
Redirects error output of this process runnable's system command to the specified file. |
void |
redirectErrorsTo(OutputStream o)
Redirects error output of this process runnable's system command to the specified stream. |
void |
redirectOutputTo(File f)
Redirects output of this process runnable's system command to the specified file. |
void |
redirectOutputTo(OutputStream o)
Redirects output of this process runnable's system command to the specified stream. |
void |
registerExceptionHandler(ExceptionHandler xh)
Registers an exception handler to deal with exceptions thrown within the run() method. |
void |
run()
Executes this process runnable's system command. |
void |
setCommand(String cmd)
Sets the command that will be executed when run() is called. |
void |
setCommand(String[] cmdarray)
Sets the command line that will be executed when run() is called. |
void |
setEnvironment(String[] envp)
Sets the environment for this process runnable's system command. |
void |
setWorkingDirectory(File dir)
Sets the working directory for this process runnable's system command. |
void |
stop()
Kills the system process spawned by the run() method if
this process runnable is currently running. |
int |
waitFor()
Waits for the system process spawned by the run() method to
terminate if this process runnable is currently running. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ProcessRunnable.Output errp
NullStream.
protected ProcessRunnable.Output outp
NullStream.
protected ProcessRunnable.Input inpt
null.
| Constructor Detail |
|---|
public ProcessRunnable(String command)
run() method will execute
the specified command.
command - the system command to executepublic ProcessRunnable(String[] cmdarray)
run() method will execute
the command made up of the specified tokens.
cmdarray - the tokens that together form the command line to execute| Method Detail |
|---|
public void setCommand(String cmd)
throws IllegalStateException
run() is called.
cmd - the system command to execute
IllegalStateException - when this process runnable is
currently running.public String getCommand()
run() is called.
null
if this process runnable's command has been specified as an array.
public void setCommand(String[] cmdarray)
throws IllegalStateException
run() is called.
cmdarray - the tokens that together form the command line to
execute
IllegalStateException - when this process runnable is
currently running.public String[] getCommandArray()
run() is called.
null
if this process runnable's command has been specified as a single string.public String getCommandAsString()
run() is called, independently of whether this command
has been specified as a single string or as an array of string tokens.
public void redirectOutputTo(OutputStream o)
throws IllegalStateException
null is passed output from the external process
will be read and discarded (the default). The specified
output stream will not be
closed by this class.
o - the output stream the program should write its output to
IllegalStateException - when this process runnable is
currently running.
public void redirectOutputTo(File f)
throws IllegalStateException
f - the file the program should write its output to
IllegalStateException - when this process runnable is
currently running.
public void redirectErrorsTo(OutputStream o)
throws IllegalStateException
null is passed output from the external process
will be read and discarded (the default). The specified
output stream will not be
closed by this class.
o - the output stream the program should write its output to
IllegalStateException - when this process runnable is
currently running.
public void redirectErrorsTo(File f)
throws IllegalStateException
f - the file the program should write its output to
IllegalStateException - when this process runnable is
currently running.
public void setEnvironment(String[] envp)
throws IllegalStateException
envp - the environment for this process runnable's system command
specified as an array of "key=value" pairs.
IllegalStateException - when this process runnable is
currently running.Runtime.exec(String[] cmd,String[] envp, File dir),
getEnvironment()public String[] getEnvironment()
"key=value" pairs.Runtime.exec(String[] cmd,String[] envp, File dir),
setEnvironment(java.lang.String[])
public void setWorkingDirectory(File dir)
throws IllegalStateException
dir - the working directory for this process runnable's system
command
IllegalStateException - when this process runnable is
currently running.Runtime.exec(String[] cmd,String[] envp, File dir),
getWorkingDirectory()public File getWorkingDirectory()
getWorkingDirectory()public void run()
run in interface Runnablepublic void registerExceptionHandler(ExceptionHandler xh)
run() method. By default any exceptions
thrown within run will be re-thrown as RuntimeExceptions.
registerExceptionHandler in interface RunnableQueue.Jobxh - an exception handlerprotected ExceptionHandler getExceptionHandler()
run() method.
registerExceptionHandler(de.mospace.lang.ExceptionHandler)public void stop()
run() method if
this process runnable is currently running.
stop in interface RunnableQueue.Job
public int waitFor()
throws InterruptedException
run() method to
terminate if this process runnable is currently running. In this case
the exit value of the currently running process is returned. Otherwise
this method has the same effect as getExitStatus().
InterruptedException - if the system process is interruptedpublic int getExitStatus()
getExitStatus in interface RunnableQueue.Jobpublic boolean isRunning()
public void readInputFrom(File f)
f - the file to read input frompublic void readInputFrom(InputStream i)
readInputFrom in interface RunnableQueue.Jobi - the stream to read input frompublic boolean hasInput()
hasInput in interface RunnableQueue.JobreadInputFrom(File),
readInputFrom(InputStream)public void clearInput()
|
Mp3dings 20100427 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||