|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.core.util.exec.ProcessExecutor
public class ProcessExecutor
Executes a process using 100% Java API.
Warning: caution should be exercised when using this class - it allows any process to be started with no security restrictions.
| Constructor Summary | |
|---|---|
ProcessExecutor()
|
|
| Method Summary | |
|---|---|
protected File |
createOutputFile(ProcessToStart process)
Creates the output file and returns its File representation. |
ProcessExecutorResults |
execute(ProcessToStart processToStart)
This executes any operating system process as described in the given start command. |
protected String[] |
getCommandLine(ProcessToStart process)
Builds the command line containing the full path to the program executable and any arguments that are to be passed to the program. |
protected String |
getFullProgramExecutablePath(ProcessToStart process)
Returns the full pathname to the program executable. |
protected File |
getInputFile(ProcessToStart process)
Gets the input file and returns its File representation. |
protected File |
getWorkingDirectory(ProcessToStart process)
Returns the full pathname to the working directory. |
protected void |
redirectStreams(ProcessToStart process,
Process childProcess)
This method redirects the stdout/stderr streams of the child process to the output log file and pipes the contents of the input file (if one was specified) to the stdin stream of the child process. |
protected Integer |
startProgram(ProcessToStart process)
Starts a child process. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ProcessExecutor()
| Method Detail |
|---|
public ProcessExecutorResults execute(ProcessToStart processToStart)
ProcessToStart.setWaitForExit(Long) to a positive, non-zero timeout
in milliseconds. On error, the exception will be returned in the returned results.
processToStart - the information on what process to start
protected Integer startProgram(ProcessToStart process)
throws Exception
ProcessToStart.getWaitForExit() is positive, non-zero. In that case, the returned value will be the exit
code of the process. If this method is told not to wait, the returned value will be null.
process - provides the information necessary to start the child process
null if this method was to only
start the process but not wait or was to wait and the wait time expired before the process exited
Exception - if any error occurs while trying to start the child process
protected void redirectStreams(ProcessToStart process,
Process childProcess)
throws IOException
This is done asynchronously so as to avoid deadlocking and to allow the main thread to continue its work.
Once the child process dies, so do the piping threads.
process - used to configure the processchildProcess - the newly spawned child process
IOException - if failed to pipe data to/from stdin/stdout
protected File createOutputFile(ProcessToStart process)
throws IOException
File representation. This is the location where the child
process' stdout/stderr output streams get redirected to. Note that if the file does not exist, it will be
created; if it does exist, the original will be renamed with a timestamp before a new file is created only if the
backup output file flag is Boolean.TRUE; otherwise it
will be overwritten.
If the output directory was not specified, a temporary location
will be used (i.e. the System property java.io.tmpdir). If the
output file name was not specified, one will be generated automatically -
using the title if one was specified.
If we are not to capture the output, this method returns
null.
process - the process to start
null)
IOException - if the output file could not be created
FileNotFoundException - the output directory does not exist or is not a valid directory
protected File getInputFile(ProcessToStart process)
throws IOException
File representation. This is the file whose data will be sent to
the child process' stdin input stream. Note that if the input file that was specified in the command does not
exist, an exception is thrown. If the command does not specify an input file, null is returned.
process - the start command
null)
IOException - if the input file could not be found
FileNotFoundException - the input directory does not exist or is not a valid directory
protected String getFullProgramExecutablePath(ProcessToStart process)
throws FileNotFoundException
process - the process to start
FileNotFoundException - if the program executable does not exist
protected File getWorkingDirectory(ProcessToStart process)
throws FileNotFoundException
null, child process inherits the parent process's current working
directory.
process - the process to start
FileNotFoundException - if the working directory does not exist
protected String[] getCommandLine(ProcessToStart process)
throws FileNotFoundException
process - the process to start
FileNotFoundException - if the program executable file does not exist
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||