nata-kit/src/main/java/com/nata/ShellKit.java
/**
     * Execute a shell command and return its output
     *
     * @param command command to execute
     * @return process executed
     */
Execute a shell command and return its output
@param command command to execute
@return process executed
Execute a shell command and return its output @param command command to execute @return process executed
public static String command(List<String> command) {
        ProcessBuilder pb = new ProcessBuilder(command).redirectErrorStream(true);
        String output = "";
        try {
            Process process = pb.start();
            IOThreadHandler outputHandler = new IOThreadHandler(
                    process.getInputStream());
            outputHandler.start();
            process.waitFor();
            outputHandler.join();
            output = outputHandler.getOutput();
        } catch (InterruptedException | IOException e) {
            e.printStackTrace();
        }
        return output;
    }
public static String command ( List < String > command ) { ProcessBuilder pb = new ProcessBuilder ( command ) . redirectErrorStream ( true ) ; String output = "" ; try { Process process = pb . start ( ) ; IOThreadHandler outputHandler = new IOThreadHandler ( process . getInputStream ( ) ) ; outputHandler . start ( ) ; process . waitFor ( ) ; outputHandler . join ( ) ; output = outputHandler . getOutput ( ) ; } catch ( InterruptedException | IOException e ) { e . printStackTrace ( ) ; } return output ; }
Execute a shell command and return its output
 @param command command to execute
 @return process executed
Execute a shell command and return its output @param command command to execute @return process executed
//set redirectErrorStream to be true to cross output streams //wait for the process to stop //in case the process stopped before the thread