Java exec executeShellCommand(String command)

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

Description

execute Shell Command

License

Apache License

Declaration

public static boolean executeShellCommand(String command) 

Method Source Code


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

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

public class Main {
    public static boolean executeShellCommand(String command) {
        try {/* www.  j a  v a2s. c  o  m*/
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            int read;
            char[] buffer = new char[4096];
            StringBuffer output = new StringBuffer();
            while ((read = reader.read(buffer)) > 0) {
                output.append(buffer, 0, read);
            }
            reader.close();
            process.waitFor();

            return true;

        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. executeProcess(String command)
  2. executeProcessAndGetOutputAsStringList(final String command)
  3. executePUT(DataInputStream sockInp, DataOutputStream sockOutp)
  4. executeServer()
  5. executeShellCmdAndReturn(String cmd)
  6. executeShellCommand(String command)
  7. executeShellCommand(String command, File dir)
  8. executeShellCommand(String commandName)
  9. executeShellScript(final String shellScript, final File tempDirectory)