// Create the stream pumpers to forward listcab's stdout and stderr to the log
// note: listcab is an interactive program, and issues prompts for every new line.
// Therefore, make it show only with verbose logging turned on.
LogOutputStream outLog = new LogOutputStream(this, Project.MSG_VERBOSE);
LogOutputStream errLog = new LogOutputStream(this, Project.MSG_ERR);
StreamPumper outPump = new StreamPumper(p.getInputStream(), outLog);
StreamPumper errPump = new StreamPumper(p.getErrorStream(), errLog);
// Pump streams asynchronously
(new Thread(outPump)).start();
(new Thread(errPump)).start();
out.write(sb.toString().getBytes());
out.flush();
out.close();
// A wild default for when the thread is interrupted
int result = DEFAULT_RESULT;
try {
// Wait for the process to finish
result = p.waitFor();
// Wait for the end of output and error streams
outPump.waitFor();
outLog.close();
errPump.waitFor();
errLog.close();
} catch (InterruptedException ie) {
log("Thread interrupted: " + ie);
}