Java Shell Command runCommand(String command)

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

Description

run Command

License

Open Source License

Declaration

public static String runCommand(String command) throws IOException, InterruptedException 

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 runCommand(String command) throws IOException, InterruptedException {
        Process p = Runtime.getRuntime().exec(command);
        p.waitFor();/*from   w  w  w . j  a v a 2  s . c  om*/

        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));

        String line = "";
        StringBuilder sb = new StringBuilder();
        while ((line = reader.readLine()) != null)
            sb.append(line + "\n");

        return sb.toString();
    }
}

Related

  1. getJavaVersion(String command)
  2. runCommand(final ProcessBuilder command)
  3. runCommand(String cmd)
  4. runCommand(String cmd)
  5. runCommand(String command)
  6. runCommand(String command, String args, String file)
  7. runCommand(String command[])
  8. runCommand(String program, ArrayList args)