public List getPortCandidates()

in agent/src/main/java/com/attachme/agent/CommandPortResolver.java [28:56]


  public List<Integer> getPortCandidates(int pid) {
    int status = 0;
    List<Integer> ans = new ArrayList<>();
    String command = portCommandHandler.createCommand(pid);
    try {
      Process proc = new ProcessBuilder()
        .command(command.split(" "))
        .redirectErrorStream(true)
        .start();
      BufferedReader script = new BufferedReader(new InputStreamReader(proc.getInputStream()));
      String line;
      Function<String, Optional<Integer>> parser = portCommandHandler.outputParser(pid);
      while ((line = script.readLine()) != null) {
        parser.apply(line).ifPresent(ans::add);
      }
      status = proc.waitFor();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    if (status != 0) {
      System.err.println("[attachme] The command " + command + " finished with status code " + status);
    }

    if (ans.isEmpty()) {
      System.err.println("[attachme] Command " + command + " could not find open ports");
    }
    return ans;
  }