Java exec execute(final String command)

Here you can find the source of execute(final String command)

Description

execute

License

Open Source License

Declaration

public static final synchronized String execute(final 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 final synchronized String execute(final String command) throws IOException, InterruptedException {
        StringBuilder output = new StringBuilder();
        Process p;/*w w  w.ja  v  a 2 s.com*/
        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).append("\n");
        }
        return output.toString();
    }
}

Related

  1. execSudoCommand(final String _sudoCmd, final String _pw)
  2. execSystemCommand(String[] commands, String executionPath)
  3. execToString(final String... args)
  4. execute(boolean returnOutput, boolean returnError, boolean throwException, String[] cmd, File dir, String[] env)
  5. execute(final String applicationName, final String workingDirectory)
  6. execute(ProcessBuilder builder, String errorMsg)
  7. execute(String cmd, String input)
  8. execute(String command)
  9. execute(String command)