Java exec executeCommand(String cmd)

Here you can find the source of executeCommand(String cmd)

Description

execute Command

License

Open Source License

Declaration

public static String executeCommand(String cmd) 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {

    public static String executeCommand(String cmd) {
        Process p;//from w  ww .j av  a2 s .  c  om
        try {
            p = Runtime.getRuntime().exec(cmd);

            InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
            StringBuffer buffer = new StringBuffer();
            for (;;) {
                int c = stdoutStream.read();
                if (c == -1) {
                    break;
                }
                buffer.append((char) c);
            }
            String outputText = buffer.toString();
            stdoutStream.close();
            return outputText;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}

Related

  1. executeComand(String[] comand)
  2. executeCommand(final ProcessBuilder pb)
  3. executeCommand(final String cmd)
  4. executeCommand(List cmdArray)
  5. executeCommand(List command)
  6. executeCommand(String cmd)
  7. executeCommand(String comand)
  8. executeCommand(String command)
  9. executeCommand(String command)