private void launchExternalProcess() {
Thread thread = new Thread(new Runnable() {
public void run() {
ExecutionInfo executionInfo = null;
ExecHandle execHandle = null;
ByteArrayOutputStream output = null;
try {
executionInfo = protocol.getExecutionInfo(getPort() );
ExecHandleBuilder builder = new ExecHandleBuilder();
builder.workingDir(executionInfo.getWorkingDirectory());
builder.commandLine((Object[]) executionInfo.getCommandLineArguments());
builder.environment(executionInfo.getEnvironmentVariables());
output = new ByteArrayOutputStream();
builder.setStandardOutput(output);
builder.setErrorOutput(output);
execHandle = builder.build();
setExternalProcess(execHandle);
execHandle.start();
}
catch (Throwable e) {
LOGGER.error("Starting external process", e);
notifyClientExited( -1, e.getMessage() );
setExternalProcess(null);
return;
}
ExecResult result = execHandle.waitForFinish();
LOGGER.debug("External process completed with exit code {}", result.getExitValue());
setExternalProcess(null); //clear our external process member variable (we're using our local variable below). This is so we know the process has already stopped.
executionInfo.processExecutionComplete();