} catch (IOException e) {
throw new CruiseControlException("Encountered an IO exception while attempting to execute '"
+ script.toString() + "'. CruiseControl cannot continue.", e);
}
StreamPumper errorPumper;
StreamPumper outPumper;
if (script instanceof StreamConsumer) {
errorPumper = new StreamPumper(p.getErrorStream(), (StreamConsumer) script);
outPumper = new StreamPumper(p.getInputStream(), (StreamConsumer) script);
} else {
errorPumper = new StreamPumper(p.getErrorStream());
outPumper = new StreamPumper(p.getInputStream());
}
new Thread(errorPumper).start();
new Thread(outPumper).start();
AsyncKiller killer = new AsyncKiller(p, timeout);
if (timeout > 0) {
killer.start();
}
try {
exitCode = p.waitFor();
killer.interrupt();
p.getInputStream().close();
p.getOutputStream().close();
p.getErrorStream().close();
} catch (InterruptedException e) {
LOG.info("Was interrupted while waiting for script to finish."
+ " CruiseControl will continue, assuming that it completed");
} catch (IOException ie) {
LOG.info("Exception trying to close Process streams.", ie);
}
outPumper.flush();
errorPumper.flush();
script.setExitCode(exitCode);
return !killer.processKilled();