int exitCode;
try {
ExecOutputHandleRunner standardOutputRunner;
ExecOutputHandleRunner errorOutputRunner;
ExecOutputHandleRunner standardInputRunner;
InputStream instr = new DisconnectableInputStream(execHandle.getStandardInput(), new DefaultExecutorFactory());
Process process;
// This big fat static lock is here for windows. When starting multiple processes concurrently, the stdout
// and stderr streams for some of the processes get stuck
synchronized (START_LOCK) {
process = processBuilder.start();
standardOutputRunner = new ExecOutputHandleRunner("read process standard output",
process.getInputStream(), execHandle.getStandardOutput());
errorOutputRunner = new ExecOutputHandleRunner("read process error output", process.getErrorStream(),
execHandle.getErrorOutput());
standardInputRunner = new ExecOutputHandleRunner("write process standard input",
instr, process.getOutputStream());
}
synchronized (lock) {
this.process = process;
}
threadPool.execute(standardInputRunner);
threadPool.execute(standardOutputRunner);
threadPool.execute(errorOutputRunner);
execHandle.started();
exitCode = process.waitFor();
instr.close();
} catch (Throwable t) {
execHandle.failed(t);
return;
}