Java exec executeCmdCommand(String command)

Here you can find the source of executeCmdCommand(String command)

Description

execute Cmd Command

License

Open Source License

Declaration

private static String executeCmdCommand(String command)
                throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    private static String executeCmdCommand(String command)
            throws IOException {
        System.out.println("Execute " + command);
        ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c",
                command);/*from   w  w  w . j  av  a2s .  c  o  m*/
        //        builder.redirectErrorStream(true);
        Process p = builder.start();
        BufferedReader r = new BufferedReader(new InputStreamReader(
                p.getInputStream()));
        StringBuilder result = new StringBuilder();
        String line;
        while (true) {
            line = r.readLine();
            if (line == null) {
                break;
            }
            result.append(line);
            System.out.println(line);
        }
        return result.toString();

    }
}

Related

  1. executeAndWait(String command)
  2. executeApplication(String filePath)
  3. executeBashScriptWithParams(ArrayList script)
  4. executeBatFile(String batFile)
  5. executeCD(String dirPath)
  6. executeCmdForReader(String cmd)
  7. executeComand(String[] comand)
  8. executeCommand(final ProcessBuilder pb)
  9. executeCommand(final String cmd)