|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecteu.beesoft.gaia.util.SystemProcess
public class SystemProcess
This class encapsulates functionality of the java.lang.Process, java.lang.ProcessBuilder and some methods from java.lang.Runtime classes. It supports to:
There is also a set of the static exec()
methods to simplify starting of the system
process.
Note, this implementation solves the problem of the Process.waitFor() method, which hangs when are not read the process streams.
Constructor Summary | |
---|---|
SystemProcess()
Default constructor, creates a new instance of the SystemProcess. |
Method Summary | |
---|---|
void |
addCommand(java.util.List<java.lang.String> cmd)
Adds each parameter from given list to the command list. |
void |
addCommand(java.lang.String... cmd)
Adds each parameter from given array to the command list. |
void |
addCommand(java.lang.String cmd)
Adds a new command parameter to the command list. |
static SystemProcess |
exec(java.util.List<java.lang.String> command,
java.io.File workingDirectory,
boolean waitForEnd)
Executes the specified command and arguments in a separate process. |
static SystemProcess |
exec(java.lang.String... command)
Executes the specified command and arguments in a separate process. |
static SystemProcess |
exec(java.lang.String[] command,
java.io.File workingDirectory,
boolean waitForEnd)
Executes the specified command and arguments in a separate process. |
static SystemProcess |
exec(java.lang.String command,
java.io.File workingDirectory,
boolean waitForEnd)
Executes the specified command in a separate process. |
java.util.List<java.lang.String> |
getCommand()
Returns the list of commands (arguments). |
java.util.Map<java.lang.String,java.lang.String> |
getEnvironment()
Returns a map of the current system environment. |
java.io.InputStream |
getErrorStream()
Gets the error stream of the process. |
int |
getExitValue()
Returns the exit value for the subprocess. |
java.io.InputStream |
getInputStream()
Gets the input stream of the process. |
java.io.OutputStream |
getOutputStream()
Gets the output stream of the subprocess. |
java.io.File |
getWorkingDirectory()
Returns the working directory set by setWorkingDirectory(File) method or null. |
void |
kill()
Kills this process, it is forcibly terminated. |
void |
mergeErrorStream()
Merges error and input stream to the one. |
void |
setWorkingDirectory(java.io.File workingDirectory)
Sets a new value for working directory. |
void |
setWorkingDirectory(java.lang.String dir)
Sets a new value for working directory. |
void |
start()
Starts system process. |
int |
waitFor()
Causes the current thread to wait, if necessary, until the process represented by this instance has terminated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SystemProcess()
Method Detail |
---|
public java.io.File getWorkingDirectory()
setWorkingDirectory(File)
method or null.
public void setWorkingDirectory(java.io.File workingDirectory)
workingDirectory
- the workingDirectory to set
java.lang.RuntimeException
- if workingDirectory
does not exist or is a file (not a directory)public void setWorkingDirectory(java.lang.String dir)
setWorkingDirectory(File)
.
dir
- the workingDirectory to set
java.lang.RuntimeException
- if workingDirectory
does not exist or is a file (not a directory)public java.util.List<java.lang.String> getCommand()
public void addCommand(java.lang.String cmd)
cmd
- - parameter to add to the command listpublic void addCommand(java.util.List<java.lang.String> cmd)
cmd
- - list of parameters to add to the command listpublic void addCommand(java.lang.String... cmd)
cmd
- - array of parameters to add to the command listpublic java.util.Map<java.lang.String,java.lang.String> getEnvironment()
public void mergeErrorStream()
public void start()
public int waitFor()
start()
method
first.
public int getExitValue()
java.lang.IllegalThreadStateException
- - if the subprocess represented by this Process object has not yet terminated.public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
Note, there is an InputStreamGobbler
used in the implementation, so output from the
running process is available after the end of the process.
public java.io.InputStream getErrorStream()
Note, there is an InputStreamGobbler
used in the implementation, so output from the
running process is available after the end of the process.
public void kill()
public static SystemProcess exec(java.lang.String... command)
This is a convenience method. It behaves in exactly the same way as the invocation
exec(command, null, false)
.
command
- - array of command and its parameters
public static SystemProcess exec(java.lang.String command, java.io.File workingDirectory, boolean waitForEnd)
This is a convenience method. It parses given command to the individul tokens (parameters)
and invokes exec(List, File, boolean)
method.
command
- - command String to executeworkingDirectory
- - working directory of the process or null if the default system directory should
be usedwaitForEnd
- - if true, method blocks while process is not finished
public static SystemProcess exec(java.lang.String[] command, java.io.File workingDirectory, boolean waitForEnd)
This is a convenience method. It converts given array to the List instance and then invokes
exec(List, File, boolean)
method.
command
- - array of command and parameters to executeworkingDirectory
- - working directory of the process or null if the default system directory should
be usedwaitForEnd
- - if true, method blocks while process is not finished
public static SystemProcess exec(java.util.List<java.lang.String> command, java.io.File workingDirectory, boolean waitForEnd)
Returns created and started instance of SystemProcess. If given argument
waitForEnd
is true, blocks while process is not finished.
command
- - list of command and parameters to executeworkingDirectory
- - working directory of the process or null if the default system directory should
be usedwaitForEnd
- - if true, method blocks while process is not finished
|
JavaGantt 2011.1 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |