Java exec executeCommand(String command)

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

Description

execute Command

License

Apache License

Declaration

public static String executeCommand(String command) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static String executeCommand(String command) {
        StringBuffer output = new StringBuffer();

        Process p;//w  ww  .java2  s .co m
        try {
            p = Runtime.getRuntime().exec(command);
            p.waitFor();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

            String line = "";
            while ((line = reader.readLine()) != null) {
                output.append(line + "\n");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return output.toString();
    }
}

Related

  1. executeCommand(String command)
  2. executeCommand(String command)
  3. executeCommand(String command)
  4. executeCommand(String command)
  5. executeCommand(String command)
  6. executeCommand(String command, boolean waitForResponse)
  7. executeCommand(String[] command, boolean wait)
  8. executeCommand1(boolean isProcessBuilder, String command)
  9. executeCommand2(boolean isProcessBuilder, String command)