Methods Summary |
---|
public java.lang.String | execute()Execute the command.
if (runner != null) {
throw new IllegalStateException(
"process.already_executed");
}
runner = new ProcessRunner(command, timeout);
Thread runnerThread = new Thread(runner);
runnerThread.start();
try {
runnerThread.join(timeout);
} catch (InterruptedException ie) {
logger.log(Level.FINEST, "process.waiter_interrupted",
getCommandString());
}
if (runnerThread.isAlive()) {
if (!runner.completed) {
logger.log(Level.FINEST, "process.interrupting",
new Object[] {new Long(timeout), getCommandString()});
runnerThread.interrupt();
try {
// Wait for 500 ms for thread to terminate
runnerThread.join(500);
} catch (InterruptedException ie) {
// Ignore this exception. Interrupted while waiting for
// runner thread to respond to interrupt() call
}
if (!runner.completed && !runner.interrupted) {
// Thread did not finish, force the status to interrupted
runner.interrupted = true;
}
}
}
if (runner.interrupted || runner.exception != null) {
if (runner.exception == null) {
// Thread did not complete but there is no exception, assume
// it did not finish because of timeout
runner.makeTimeoutException();
}
throw runner.exception;
}
return runner.stdout.toString();
|
public java.lang.String | executeAgain()Execute the process again. All results of previous execution are lost.
runner = null;
return execute();
|
public java.lang.String | getCommandString()Get command as a string.
String cmdString = null;
if (runner != null) {
cmdString = runner.getCommandString();
}
if (cmdString == null) {
StringBuffer buf = new StringBuffer();
for (int i = 0; i < command.length; i++) {
buf.append(command[i] + " ");
}
cmdString = buf.toString();
}
return cmdString;
|
public int | getExitCode()Get exit code of the process.
int exitCode = 0;
if (runner != null && runner.completed) {
exitCode = runner.exitCode;
} else {
throw new IllegalStateException(
"process.not_yet_executed");
}
return exitCode;
|
public java.lang.String | getStderr()Get standard error of the process.
String stderr = null;
if (runner != null) {
stderr = runner.stderr.toString();
}
return stderr;
|
public java.lang.String | getStdout()Get standard output of the process.
String stdout = null;
if (runner != null) {
stdout = runner.stdout.toString();
}
return stdout;
|
public long | getTimeout()Get timeout value (in milliseconds)
return timeout;
|
public boolean | isCompleted()Is process execution complete.
boolean completed = false;
if (runner != null) {
completed = runner.completed;
}
return completed;
|
public boolean | isInterrupted()Is (was) process execution interrupted.
boolean interrupted = false;
if (runner != null) {
interrupted = runner.interrupted;
}
return interrupted;
|
public void | setTimeout(long timeout)Set timeout to specified value.
if (timeout >= 0) {
this.timeout = timeout;
} else {
throw new IllegalArgumentException(
"process.invalid_timeout_value " + new Long(timeout));
}
|