code: public static boolean runCommand(final Process p, final OutputStream output, final OutputStream error,
              final List<String> doNotPrintStrings) {
          final StreamRedirector errorStream = new StreamRedirector(p.getErrorStream(), error, doNotPrintStrings);
          final StreamRedirector outputStream = new StreamRedirector(p.getInputStream(), output, doNotPrintStrings);
  
          errorStream.start();
          outputStream.start();
  
          try {
              final boolean retValue = p.waitFor() == 0;
  
              // give the threads time to collect the final output from the Process
              errorStream.join();
              outputStream.join();
  
              return retValue;
          } catch (final InterruptedException ex) {
              LOG.debug("Command execution Intercepted", ex);
              return false;
          }
      }
docs: Run a Process, and read the various streams so there is not a buffer
  overrun.
  
  @param p                 The Process to be executed
  @param output            The Stream to receive the Process' output stream
  @param error             The Stream to receive the Process' error stream
  @param doNotPrintStrings A collection of strings that should not be
  dumped to std.out
  @return true if the Process returned 0, false otherwise