|
OOoRunner test harness | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
helper
Class ProcessHandler
java.lang.Object | +--helper.ProcessHandler
- public class ProcessHandler
- extends Object
Class provides convenient way for running external program handle its standard streams, control execution and check results. Instance of this class must be created only for a single execution. If you need to execute the same command again you should create a new instance for this.
Constructor Summary | |
ProcessHandler(String cmdLine)
Creates instance with specified external command. |
|
ProcessHandler(String cmdLine,
File workDir)
Creates instance with specified external command which will be executed in the some work directory. |
|
ProcessHandler(String cmdLine,
PrintWriter log)
Creates instance with specified external command and log stream where debug info is printed and output of external command. |
|
ProcessHandler(String cmdLine,
PrintWriter log,
File workDir,
String[] envVars)
Creates instance with specified external command which will be executed in the some work directory and log stream where debug info and output of external command is printed . |
|
ProcessHandler(String cmdLine,
PrintWriter log,
File workDir,
String[] envVars,
long timeOut)
Creates instance with specified external command which will be executed in the some work directory and |
Method Summary | |
protected void |
execute()
|
boolean |
executeAsynchronously()
Executes the command immediately returns. |
boolean |
executeSynchronously()
Executes the command and returns only when the process exits. |
protected void |
flushInput()
|
String |
getErrorText()
Returns the text output by external command to stderr. |
int |
getExitCode()
Returns exit code of the external command. |
String |
getOutputText()
Returns the text output by external command to stdout. |
boolean |
isFinished()
Returns the information about the final state of command execution. |
boolean |
isStarted()
Returns information about was the command started or not. |
boolean |
isTimedOut()
|
void |
kill()
|
void |
printInputText(String str)
Prints the string specified to sdtin of external command. |
boolean |
waitFor()
This method is useful when the process was executed asynchronously. |
boolean |
waitFor(long timeout)
This method is useful when the process was executed asynchronously. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
ProcessHandler
public ProcessHandler(String cmdLine)
- Creates instance with specified external command. Debug info and output of external command is printed to stdout.
ProcessHandler
public ProcessHandler(String cmdLine, PrintWriter log)
- Creates instance with specified external command and log stream where debug info is printed and output of external command.
ProcessHandler
public ProcessHandler(String cmdLine, File workDir)
- Creates instance with specified external command which will be executed in the some work directory. Debug info and output of external commandis printed to stdout.
ProcessHandler
public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars)
- Creates instance with specified external command which will be executed in the some work directory and log stream where debug info and output of external command is printed . The specified environment variables are set for the new process. If log stream is null, logging is printed to stdout.
ProcessHandler
public ProcessHandler(String cmdLine, PrintWriter log, File workDir, String[] envVars, long timeOut)
- Creates instance with specified external command which
will be executed in the some work directory and
- Parameters:
log
- log stream where debug info and output of external command is printed .workDir
- The working directory of the new processenvVars
- The specified environment variables are set for the new process. If log stream is null, logging is printed to stdout.timeOut
- When started sychronisly, the maximum time the process will live. When the process being destroyed a log will be written out. It can be asked onisTimedOut()
if it has been terminated. timeOut > 0 Waits specified time in miliSeconds for process to exit and return its status. timeOut = 0 Waits for the process to end regulary timeOut < 0 Kills the process immediately
Method Detail |
isTimedOut
public boolean isTimedOut()
executeSynchronously
public boolean executeSynchronously()
- Executes the command and returns only when the process
exits.
- Returns:
true
if process was successfully started and correcly exits (exit code doesn't affect to this result).
executeAsynchronously
public boolean executeAsynchronously()
- Executes the command immediately returns. The process
remains in running state. Control of its state should
be made by
waitFor
methods.- Returns:
true
if process was successfully started.
kill
public void kill()
execute
protected void execute()
waitFor
public boolean waitFor()
- This method is useful when the process was executed
asynchronously. Waits for process to exit and return
its result.
- Returns:
true
if process correctly exited (exit code doesn't affect to this result).
waitFor
public boolean waitFor(long timeout)
- This method is useful when the process was executed
asynchronously. Waits during specified time for process
to exit and return its status.
- Parameters:
timeOut
- > 0 Waits specified time in miliSeconds for process to exit and return its status. = 0 Waits for the process to end regulary < 0 Kills the process immediately- Returns:
true
if process correctly exited (exit code doesn't affect to this result).
flushInput
protected void flushInput()
getOutputText
public String getOutputText()
- Returns the text output by external command to stdout.
getErrorText
public String getErrorText()
- Returns the text output by external command to stderr.
printInputText
public void printInputText(String str)
- Prints the string specified to sdtin of external
command. '\n' is not added so if you need you
should terminate the string with '\n'.
The method can also be called before the command starts its execution. Then the text is buffered and transfered to command when it will be started.
isStarted
public boolean isStarted()
- Returns information about was the command started or
not.
- Returns:
true
if the external command was found and successfully started.
isFinished
public boolean isFinished()
- Returns the information about the final state of command
execution.
- Returns:
true
if the command correctly starts, exits and was not interrupted due to timeout.
getExitCode
public int getExitCode()
- Returns exit code of the external command.
- Returns:
- exit code of command if it was finished, -1 if not.
|
OOoRunner test harness | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |