private static void executeLsof(final StringBuilder existingNetstatInfo,
      final String lineSeparator) {
    existingNetstatInfo.append("################ ").append(LSOF_COMMAND)
        .append(" output ###################").append(lineSeparator);

    if (isLinux() || isMacOSX() || isSolaris()) {
      List<String> cmdOptionsList = new ArrayList<>();
      cmdOptionsList.add(LSOF_COMMAND);
      cmdOptionsList.add("-n");
      cmdOptionsList.add("-P");

      ProcessBuilder procBuilder = new ProcessBuilder(cmdOptionsList);

      Process lsof = null;
      InputStreamReader reader = null;
      BufferedReader breader = null;
      try {
        lsof = procBuilder.start();
        reader = new InputStreamReader(lsof.getInputStream());
        breader = new BufferedReader(reader);
        String line;

        while ((line = breader.readLine()) != null) {
          existingNetstatInfo.append(line).append(lineSeparator);
        }
      } catch (IOException e) {
        // TODO: change this to keep the full stack trace
        String message = e.getMessage();
        if (message.contains("error=2, No such file or directory")) {
          existingNetstatInfo
              .append(CliStrings.format(CliStrings.NETSTAT__MSG__COULD_NOT_EXECUTE_0_REASON_1,
                  LSOF_COMMAND, CliStrings.NETSTAT__MSG__LSOF_NOT_IN_PATH));
        } else {
          existingNetstatInfo
              .append(CliStrings.format(CliStrings.NETSTAT__MSG__COULD_NOT_EXECUTE_0_REASON_1,
                  LSOF_COMMAND, e.getMessage()));
        }
      } finally {
        releaseResources(lsof, reader, breader);
        existingNetstatInfo.append(lineSeparator); // additional new line
      }
    } else {
      existingNetstatInfo.append(CliStrings.NETSTAT__MSG__NOT_AVAILABLE_FOR_WINDOWS)
          .append(lineSeparator);
    }
  }
Executes 'netstat' OS command & returns the result as compressed bytes.

@since GemFire 7.0
geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/functions/NetstatFunction.java