public static ProcessReturn procWaitWithProcessReturn (Process process, final long timeout) throws OSHelperException {
		long endTime = Calendar.getInstance ().getTimeInMillis () + timeout;

		boolean terminatedByItself = false;

		ProcessReturn processReturn = new ProcessReturn ();
		while (Calendar.getInstance ().getTimeInMillis () < endTime) {
			try {
				InputStream stdoutIs = process.getInputStream ();
				processReturn.stdout = readInputStreamAsString (stdoutIs);

				InputStream stderrIs = process.getErrorStream ();
				processReturn.stderr = readInputStreamAsString (stderrIs);

				processReturn.exitCode = process.exitValue ();
				processReturn.exitStatus = ProcessReturn.osh_PROCESS_EXITED_BY_ITSELF;

				terminatedByItself = true;
			} catch (IllegalThreadStateException ex) {	// the process has not yet terminated
				terminatedByItself = false;
			}
			if (terminatedByItself) {
				break;
			}
		}
		if (!terminatedByItself) {
			process.destroy ();

			try {
				InputStream stdoutIs = process.getInputStream ();
				processReturn.stdout = readInputStreamAsString (stdoutIs);

				InputStream stderrIs = process.getErrorStream ();
				processReturn.stderr = readInputStreamAsString (stderrIs);

				processReturn.exitCode = process.waitFor ();
			} catch (InterruptedException ex) {
				throw new OSHelperException (ex);
			}

			processReturn.exitStatus = ProcessReturn.osh_PROCESS_KILLED_BY_TIMEOUT;
		}

		return processReturn;
	}
public static ProcessReturn procWaitWithProcessReturn ( Process process , final long timeout ) throws OSHelperException { long endTime = Calendar . getInstance ( ) . getTimeInMillis ( ) + timeout ; boolean terminatedByItself = false ; ProcessReturn processReturn = new ProcessReturn ( ) ; while ( Calendar . getInstance ( ) . getTimeInMillis ( ) < endTime ) { try { InputStream stdoutIs = process . getInputStream ( ) ; processReturn . stdout = readInputStreamAsString ( stdoutIs ) ; InputStream stderrIs = process . getErrorStream ( ) ; processReturn . stderr = readInputStreamAsString ( stderrIs ) ; processReturn . exitCode = process . exitValue ( ) ; processReturn . exitStatus = ProcessReturn . osh_PROCESS_EXITED_BY_ITSELF ; terminatedByItself = true ; } catch ( IllegalThreadStateException ex ) { terminatedByItself = false ; } if ( terminatedByItself ) { break ; } } if ( ! terminatedByItself ) { process . destroy ( ) ; try { InputStream stdoutIs = process . getInputStream ( ) ; processReturn . stdout = readInputStreamAsString ( stdoutIs ) ; InputStream stderrIs = process . getErrorStream ( ) ; processReturn . stderr = readInputStreamAsString ( stderrIs ) ; processReturn . exitCode = process . waitFor ( ) ; } catch ( InterruptedException ex ) { throw new OSHelperException ( ex ) ; } processReturn . exitStatus = ProcessReturn . osh_PROCESS_KILLED_BY_TIMEOUT ; } return processReturn ; }
Waits for a specified process to terminate for the specified amount of
milliseconds. If it is not terminated in the desired time, it is
terminated explicitly.

NOT TESTED!!!

@param process
@param timeout
@return
@throws OSHelperException