Skip to content

Instantly share code, notes, and snippets.

@philipz
Created September 11, 2015 09:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipz/f3348e7843994bdd56f0 to your computer and use it in GitHub Desktop.
Save philipz/f3348e7843994bdd56f0 to your computer and use it in GitHub Desktop.
Java Runtime.getRuntime().exec() Example
package api;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Exec {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String result = "";
		try {
		    // Execute command
		    String command = "k:\\curl.exe -d login_name=mohwtest -d login_passwd=12345 --insecure https://mohw.cyberhood.net.tw/xml_import.php";
		    Process child = Runtime.getRuntime().exec(command);
		    DataInputStream in = new DataInputStream(
                    child.getInputStream());
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(in));
            String line;
            while ((line = br.readLine()) != null) {
            	result +=line;
            }
            in.close();
		} catch (IOException e) {
		}
		System.out.println(result);
	}

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment