Here you can find the source of executeCommand1(boolean isProcessBuilder, String command)
public static String executeCommand1(boolean isProcessBuilder, String command)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; public class Main { public static String executeCommand1(boolean isProcessBuilder, String command) { try {/* w ww. j a v a 2 s . c o m*/ // ProcessBuilder broker = new ProcessBuilder("javac.exe", // "test.java", "src\\Broker\\"); //ProcessBuilder broker = new ProcessBuilder("cmd","-c","dir"); ProcessBuilder broker = new ProcessBuilder("cmd", "-c", "dir"); Process runBroker = broker.start(); Reader reader = new InputStreamReader(runBroker.getInputStream()); int ch; while ((ch = reader.read()) != -1) System.out.print((char) ch); reader.close(); runBroker.waitFor(); System.out.println("Program complete"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }