title: Why can't I get the output of curl command?
body: <p>I am trying to get the output of <code>curl</code> command in java.</p>
  
  <p>I am able to execute the same <code>curl</code> command manually through terminal and obtain the output but when I try to execute through java code as below, the output obtained is null. </p>
  
  <p>I could use Apache <code>HttpClient</code> for the same, but I want to try and use this curl cli.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.util.Arrays;
  
  public class MyCurlClient {
  
    public static void main(String[] args) {
      MyCurlClient obj = new MyCurlClient();
  
      // in mac oxs
      // String command = "ping -c 5 " + domainName;
      String command = "curl "
          + "'http://localhost:8080/auth/login' -H 'Origin:   http://localhost:9000' --data-binary '{\"username\":\"policy-engine\",\"password\":\"openstack\"}' --compressed";
  
      String output = obj.executeCommand(command);
      System.out.println(output);
    }
  
    private String executeCommand(String command) {
      StringBuffer output = new StringBuffer();
  
      Process p;
      try {
        p = Runtime.getRuntime().exec(command);
        p.waitFor();
        BufferedReader reader = new BufferedReader(new InputStreamReader(
            p.getInputStream()));
        System.out.println(reader.readLine()); // value is NULL
        String line = "";
        while ((line = reader.readLine()) != null) {
          System.out.println(line);
          output.append(line + "\n");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return output.toString();
    }
  }
  </code></pre>