Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8260275

JMH Hangs on ProcessBuilder executing httpie command

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      httpie tool is a tool for debugging web APIs. When I try to test the performance of ProcessBuilder by using JMH calling an external process "httpie -v google.com", it hangs forever even I intended to consume the output stream.

      Another weird thing is that there is no issue when I run by commands but failed with IntelliJ.


      ---------- BEGIN SOURCE ----------
      package org.benchmark;


      import java.io.*;
      import java.util.Arrays;
      import java.util.List;
      import java.util.Scanner;
      public class runProcessBuilder {
          public static void main(String[] args) {
              try {
                  runProcess();
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
          private static File NULL_FILE = new File(
                  (System.getProperty("os.name")
                          .startsWith("Windows") ? "NUL" : "/dev/null")
          );
          public static int runProcess() throws IOException, InterruptedException {
              String cmd = "https -h google.com";
              List<String> commandList = Arrays.asList(cmd.split(" "));
              ProcessBuilder pb = new ProcessBuilder(commandList).inheritIO();
      // pb.redirectOutput(ProcessBuilder.Redirect.DISCARD);
      // pb.redirectError(ProcessBuilder.Redirect.DISCARD);
              pb.redirectOutput(NULL_FILE);
              Process p = pb.start();
              return p.waitFor();
          }
      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: