setExitCode(rc); if (_printToConsole) System.out.println("[" + _pName + " " + threadName + "]: completed (rc = " + rc + ")");
/** * Constructor that takes a given <code>Process</code> object, a given process name, and a * given <code>boolean</code> flag that enables/disables console printing. If the given * process name is <code>null</code>, the default process name is assigned. * * @param aProcess * The given <code>Process</code> object. * @param procName * The given process name. * @param printToConsole * <code>boolean</code> flag that enables/disables console printing. */ public Runner(Process aProcess, String procName, boolean printToConsole) { // get next process number synchronized (Runner.class) { __processNumber++; } _process = aProcess; _pName = (procName != null) ? procName : DEF_PROC_NAME + Integer.toString(__processNumber); _errThread = new Thread(this, "ERR@Runner"); _outThread = new Thread(this, "OUT@Runner"); _stdOut = new StringWriter(); _stdErr = new StringWriter(); _printToConsole = printToConsole; start(); }
/** * Allows the caller to wait for the completion of the process, but no longer than a given * timeout value. * * @param timeout * The given timeout value (ms). * @return Process exit code or <code>Integer.MAX_VALUE</code>, if the process has not * finished yet. */ public int waitFor(long timeout) { synchronized (this) { if (getExitCode() == Integer.MAX_VALUE) { try { this.wait(timeout); } catch (InterruptedException e) { } } } return getExitCode(); } } // end of Runner
/** * Allows the caller to wait for the completion of the process. * * @return Process exit code. */ public int waitFor() { return waitFor(0); }