Exec shell cmd


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Exec {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello World! input url for 'curl -X POST' [http://127.0.0.1/]");
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String str = input.readLine();
        String url = str.length() > 1 ? str : "http://127.0.0.1/ ";
        String command = "curl -X POST -V " + url + " --data foo1=bar1&foo2=bar2";
        Process proc = Runtime.getRuntime().exec(command);

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

        System.out.println("\n========== OUTPUT :  \n");
        String s = null;
        while ((s = stdInput.readLine()) != null) {
            System.out.println(s);
        }
        System.out.println("\n========== ERROR :  \n");
        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }

    }
}