code: public static InputStream getCommandResult(
  			CommandLine cmdLine, File dir, int expectedExit,
  			long timeout, InputStream input) throws IOException {
  		DefaultExecutor executor = getDefaultExecutor(dir, expectedExit, timeout);
  
  		try (ByteArrayOutputStream outStr = new ByteArrayOutputStream()) {
  			executor.setStreamHandler(new PumpStreamHandler(outStr, outStr, input));
  			try {
  				execute(cmdLine, dir, executor, null);
  
  				return new ByteArrayInputStream(outStr.toByteArray());
  			} catch (IOException e) {
  				log.warning("Had output before error: " + new String(outStr.toByteArray()));
  				throw new IOException(e);
  			}
  		}
  	}
docs: Run the given commandline in the given directory and provide the given input to the command.
  Also verify that the tool has the expected exit code and does finish in the timeout.
  
  Note: The resulting output is stored in memory, running a command
  which prints out a huge amount of data to stdout or stderr will
  cause memory problems.
  
  @param cmdLine The commandline object filled with the executable and command line arguments
  @param dir The working directory for the command
  @param expectedExit The expected exit value or -1 to not fail on any exit value
  @param timeout The timeout in milliseconds or ExecuteWatchdog.INFINITE_TIMEOUT
  @param input Input for the command-execution
  @return An InputStream which provides the output of the command.
  
  @throws IOException Execution of sub-process failed or the
  sub-process returned a exit value indicating a failure