{
pb.environment().put(variable, env.get(variable));
}
}
Process p = pb.start();
CopyJob inputStreamJob = new CopyJob(p.getInputStream(), os == null ? System.out : os);
CopyJob errorStreamJob = new CopyJob(p.getErrorStream(), System.err);
// unfortunately the following threads are needed because of Windows behavior
System.out.println("Process input stream:");
System.err.println("Process error stream:");
Thread inputJob = new Thread(inputStreamJob);
Thread outputJob = new Thread(errorStreamJob);
try
{
inputJob.start();
inputJob.join(5000);
outputJob.start();
outputJob.join(5000);
int statusCode = p.waitFor();
String fallbackMessage = "Process did exit with status " + statusCode;
assertTrue(message != null ? message : fallbackMessage, statusCode == 0);
}
catch (InterruptedException ie)
{
ie.printStackTrace(System.err);
}
finally
{
inputStreamJob.kill();
errorStreamJob.kill();
p.destroy();
}
}