code: public static void exec(ProcessBuilder pb) throws IOException
      {
          Process p = pb.start();
          try
          {
              int errCode = p.waitFor();
              if (errCode != 0)
              {
                  BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
                  BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                  StringBuilder sb = new StringBuilder();
                  String str;
                  while ((str = in.readLine()) != null)
                      sb.append(str).append(System.getProperty("line.separator"));
                  while ((str = err.readLine()) != null)
                      sb.append(str).append(System.getProperty("line.separator"));
                  throw new IOException("Exception while executing the command: "+ StringUtils.join(pb.command(), " ") +
                                        ", command error Code: " + errCode +
                                        ", command output: "+ sb.toString());
              }
          }
          catch (InterruptedException e)
          {
              throw new AssertionError(e);
          }
      }
docs: Starts and waits for the given @param pb to finish.
  @throws java.io.IOException on non-zero exit code