try {
// running cmd
Process process = builder.start();
Thread t1 = new InputStreamToFileWriter(process.getInputStream(), app.getStandardOutput());
Thread t2 = new InputStreamToFileWriter(process.getErrorStream(), app.getStandardError());
// start output threads
t1.setDaemon(true);
t2.setDaemon(true);
t1.start();
t2.start();
// wait for the process (application) to finish executing
int returnValue = process.waitFor();
// make sure other two threads are done
t1.join();
t2.join();
/*
* check return value. usually not very helpful to draw conclusions based on return values so don't bother.
* just provide warning in the log messages
*/