Package ca.uqac.lif.cep.provenance
Class CommandRunner
- java.lang.Object
-
- java.lang.Thread
-
- ca.uqac.lif.cep.provenance.CommandRunner
-
- All Implemented Interfaces:
java.lang.Runnable
public class CommandRunner extends java.lang.Thread
Facilitates the execution of an external command and the collection of its output
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
CommandRunner.StreamGobbler
Constantly reads an input stream and captures its content.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]
m_command
protected int
m_errorCode
protected CommandRunner.StreamGobbler
m_stderrGobbler
protected java.lang.String
m_stdin
protected CommandRunner.StreamGobbler
m_stdoutGobbler
protected boolean
m_stop
-
Constructor Summary
Constructors Constructor Description CommandRunner(java.lang.String[] command)
Creates a CommandRunner to run a command.CommandRunner(java.lang.String[] command, java.lang.String stdin)
Creates a CommandRunner to run a command.CommandRunner(java.util.List<java.lang.String> command, java.lang.String stdin)
Creates a CommandRunner to run a command.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
getBytes()
Gets the contents of stdout sent by the command as an array of bytesint
getErrorCode()
Gets the return code of the command.java.lang.String
getString()
Gets the contents of stdout sent by the command as a stringvoid
run()
static byte[]
runAndGet(java.lang.String[] command, java.lang.String inputs)
static byte[]
runAndGet(java.lang.String command, java.lang.String inputs)
void
stopCommand()
Interrupts the execution of the command-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
m_command
protected java.lang.String[] m_command
-
m_stdin
protected java.lang.String m_stdin
-
m_stop
protected volatile boolean m_stop
-
m_stdoutGobbler
protected CommandRunner.StreamGobbler m_stdoutGobbler
-
m_stderrGobbler
protected CommandRunner.StreamGobbler m_stderrGobbler
-
m_errorCode
protected int m_errorCode
-
-
Constructor Detail
-
CommandRunner
public CommandRunner(java.util.List<java.lang.String> command, java.lang.String stdin)
Creates a CommandRunner to run a command.- Parameters:
command
- The command to runstdin
- If not set to null, this string will be sent to the stdin of the command being run
-
CommandRunner
public CommandRunner(java.lang.String[] command, java.lang.String stdin)
Creates a CommandRunner to run a command.- Parameters:
command
- The command to runstdin
- If not set to null, this string will be sent to the stdin of the command being run
-
CommandRunner
public CommandRunner(java.lang.String[] command)
Creates a CommandRunner to run a command.- Parameters:
command
- The command to run
-
-
Method Detail
-
runAndGet
public static byte[] runAndGet(java.lang.String[] command, java.lang.String inputs)
-
runAndGet
public static byte[] runAndGet(java.lang.String command, java.lang.String inputs)
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
getBytes
public byte[] getBytes()
Gets the contents of stdout sent by the command as an array of bytes- Returns:
- The contents of stdout
-
getString
public java.lang.String getString()
Gets the contents of stdout sent by the command as a string- Returns:
- The contents of stdout
-
getErrorCode
public int getErrorCode()
Gets the return code of the command. Generally 0 indicates that everything was OK; a non-zero value indicates an error.- Returns:
- The return code
-
stopCommand
public void stopCommand()
Interrupts the execution of the command
-
-