Class CmdExecutor
- All Implemented Interfaces:
Serializable
,Runnable
If the process cannot be created, is aborted, is externally
interrupted, or terminates normally or with failure, a listener
function is notified, with an identifier of the event that
occurred. The exit value of the process can be retrieved with
getResult()
as an Integer
.
The output of the process (stdout
and
stderr
) is copied and also stored in internal
buffers, which can be accessed to check the process result.
- Since:
- 2007.02.10
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCmdExecutor
(String[] command, ActionListener listener) Create a command executor. -
Method Summary
Modifier and TypeMethodDescriptionint
Get the exit value of the executed command.String[]
Get the command to execute as a process.Get the error stream data of the process.Get the last line of the error stream data of the process.Get the last line of the output stream data of the process.Get the output stream data of the process.void
run()
Function for thread execution.Methods inherited from class util.Executor
abort, getMessage, getStatus, start
-
Constructor Details
-
CmdExecutor
Create a command executor.On termination, the listener is notified. The identifier of the action event that is passed to the listener is
OK
if the process terminated successfully,ABORTED
if the process was aborted by a call to theabort()
function,INTERRUPTED
if the process was externally interrupted, andFAILED
if the process could not be started it returned a non-zero exit code.- Parameters:
command
- the command to be executedlistener
- the listener to be notified on termination- Since:
- 2007.02.10 (Christian Borgelt)
-
-
Method Details
-
run
public void run()Function for thread execution. -
getCommand
Get the command to execute as a process.- Returns:
- the command to execute as a process
- Since:
- 2007.02.10 (Christian Borgelt)
-
exitValue
public int exitValue()Get the exit value of the executed command.The exit value of the command is available only after the process terminated, that is, after the status of the executor has changed to either
OK
orFAILED
. Note that in case the command could not be started (and thus could not produce an exit value), this function returns 0.- Returns:
- the exit value of the executed command
- Since:
- 2007.05.03 (Christian Borgelt)
-
getOutputData
Get the output stream data of the process.This function may be called any time and yields the output of the process (to the standard output stream) that has been generated up to that point. If the process has not been started yet, the result is
null
.- Returns:
- the output stream data of the process as a string
- Since:
- 2007.02.10 (Christian Borgelt)
-
getLastOutputLine
Get the last line of the output stream data of the process.- Returns:
- the last line of the output stream data of the process
- Since:
- 2007.02.10 (Christian Borgelt)
- See Also:
-
getErrorData
Get the error stream data of the process.This function may be called any time and yields the output of the process (to the standard error stream) that has been generated up to that point. If the process has not been started yet, the result is
null
.- Returns:
- the error stream data of the process as a string
- Since:
- 2007.02.10 (Christian Borgelt)
-
getLastErrorLine
Get the last line of the error stream data of the process.- Returns:
- the last line of the error stream data of the process
- Since:
- 2007.02.10 (Christian Borgelt)
- See Also:
-