// Unfortunately there can be buffer overflow problems if there are
// not threads consuming stdout/stderr, seen that with workspace-
// control create commands on certain platforms.
processStderrStream = process.getErrorStream();
final FutureTask stderrConsumer = new FutureTask(
new StreamConsumer(processStderrStream));
processStdoutStream = process.getInputStream();
final FutureTask stdoutConsumer = new FutureTask(
new StreamConsumer(processStdoutStream));
executor.submit(stdoutConsumer);
executor.submit(stderrConsumer);
if (stdin != null) {
if (traceLog) {
logger.trace("stdin provided");
}
BufferedWriter in = null;
OutputStreamWriter osw = null;
OutputStream os = null;
try {
os = process.getOutputStream();
osw = new OutputStreamWriter(os);
in = new BufferedWriter(osw);
in.write(stdin);
in.newLine();
in.flush();
} finally {
if (in != null) {
in.close();
}
if (osw != null) {
osw.close();
}
if (os != null) {
os.close();
}
}
if (traceLog) {
logger.trace("stdin sent");
}
} else {
OutputStream os = null;
try {
os = process.getOutputStream();
} finally {
if (os != null) {
os.close();
}
}
}
final int returnCode;
try {
returnCode = process.waitFor();
} catch (InterruptedException exp) {
logger.error("Interupped exp thrown ", exp);
throw new WorkspaceException("Interrupted: ", exp);
}
if (eventLog && event) {
logger.info(Lager.ev(trackingID) + "Return code is " + returnCode);
} else if (traceLog && event) {
logger.trace("Return code is " + returnCode);
}
try {
stdout = (String) stdoutConsumer.get(60L, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error(e.getMessage());
}
try {