code: public static ProcessExecutionResult getResultFromProcess(String[] args) {
      try {
        Process process = Runtime.getRuntime().exec(args);
        StringBuilder outputSb = new StringBuilder();
        try (BufferedReader processOutputReader = new BufferedReader(
            new InputStreamReader(process.getInputStream()))) {
          String line;
          while ((line = processOutputReader.readLine()) != null) {
            outputSb.append(line);
            outputSb.append(LINE_SEPARATOR);
          }
        }
        StringBuilder errorSb = new StringBuilder();
        try (BufferedReader processErrorReader = new BufferedReader(
            new InputStreamReader(process.getErrorStream()))) {
          String line;
          while ((line = processErrorReader.readLine()) != null) {
            errorSb.append(line);
            errorSb.append(LINE_SEPARATOR);
          }
        }
        process.waitFor();
        return new ProcessExecutionResult(process.exitValue(), outputSb.toString().trim(),
            errorSb.toString().trim());
      } catch (IOException e) {
        System.err.println("Failed to execute command.");
        return new ProcessExecutionResult(1, "", e.getMessage());
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        System.err.println("Interrupted.");
        return new ProcessExecutionResult(1, "", e.getMessage());
      }
    }
docs: Executes a command in another process and check for its execution result.
  
  @param args array representation of the command to execute
  @return {@link ProcessExecutionResult} including the process's exit value, output and error