public Process waitForProcessFinished() throws IOException, IllegalStateException { if (currentProcess == null) throw new IllegalStateException("No running process"); // Wait for the command to complete try { currentProcess.waitFor(); } catch (InterruptedException e) { logger.error( "Thread was interrupted while executing command \"" + this.toString() + "\".", e); } // make sure last outputs are also captured, even if no new-line was at the // end... stdOutGobbler.readRemainder(); stdErrGobbler.readRemainder(); // Just to be compatible return currentProcess; }