private void executeCommand(String command, Map<String, String> envOverrides) {
    ensureShutdownHookInstalled();
    LOG.debug("Command : " + command);

    try {
      String[] envp = null;
      if (envOverrides != null) {
        Map<String, String> map = new HashMap<>(System.getenv());
        map.putAll(envOverrides);
        envp = new String[map.size()];
        int idx = 0;
        for (Map.Entry<String, String> e : map.entrySet()) {
          envp[idx++] = e.getKey() + "=" + e.getValue();
        }
      }

      Process p = Runtime.getRuntime().exec(command, envp);

      BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
      BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

      // read the output from the command
      String s = null;
      while ((s = stdInput.readLine()) != null) {
        System.out.println(s);
      }

      // read any errors from the attempted command
      while ((s = stdError.readLine()) != null) {
        System.out.println(s);
      }
    } catch (IOException e) {
      LOG.error("Error running: " + command, e);
    }
  }
Generates a list of random port numbers in the sorted order. A sorted order makes sense if we
ever want to refer to these servers by their index in the returned array, e.g. server #0, #1,
etc.
hbase-diagnostics/src/test/java/org/apache/hadoop/hbase/util/ProcessBasedLocalHBaseCluster.java