Java exec executeCommand(String command)

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

Description

execute Command

License

Open Source License

Declaration

public static String executeCommand(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 {
    public static String executeCommand(String command) throws IOException {
        Process process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", command });

        BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));

        StringBuilder output = new StringBuilder();
        String line;//  w  w w  . j a  v a  2  s  . c  o m
        while ((line = input.readLine()) != null) {
            output.append(line);
            output.append("\n");
        }
        input.close();

        return output.toString();

    }
}

Related

  1. executeCommand(String cmd)
  2. executeCommand(String cmd)
  3. executeCommand(String comand)
  4. executeCommand(String command)
  5. executeCommand(String command)
  6. executeCommand(String command)
  7. executeCommand(String command)
  8. executeCommand(String command)
  9. executeCommand(String command, boolean waitForResponse)