Java exec executeCommand1(boolean isProcessBuilder, String command)

Here you can find the source of executeCommand1(boolean isProcessBuilder, String command)

Description

execute Command

License

Apache License

Declaration

public static String executeCommand1(boolean isProcessBuilder, String command) 

Method Source Code

//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;
    }
}

Related

  1. executeCommand(String command)
  2. executeCommand(String command)
  3. executeCommand(String command)
  4. executeCommand(String command, boolean waitForResponse)
  5. executeCommand(String[] command, boolean wait)
  6. executeCommand2(boolean isProcessBuilder, String command)
  7. executeCommandAndExtractStdOut(String cmd)
  8. executeCommandForceDir(String baseCommand, String osPath, File file)
  9. executeCommandLine(String command)