Java exec executeCommandAndExtractStdOut(String cmd)

Here you can find the source of executeCommandAndExtractStdOut(String cmd)

Description

execute Command And Extract Std Out

License

LGPL

Declaration

public static String executeCommandAndExtractStdOut(String cmd) throws IOException, InterruptedException 

Method Source Code


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

import java.io.BufferedReader;

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

public class Main {
    public static String executeCommandAndExtractStdOut(String cmd) throws IOException, InterruptedException {

        String line;//from www  . j a v  a 2 s .c om
        Process p = Runtime.getRuntime().exec(cmd);
        BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
        StringBuilder allS = new StringBuilder();
        while ((line = bri.readLine()) != null) {
            allS.append(line + "\n");
        }
        bri.close();

        p.waitFor();
        return allS.toString();

    }
}

Related

  1. executeCommand(String command)
  2. executeCommand(String command, boolean waitForResponse)
  3. executeCommand(String[] command, boolean wait)
  4. executeCommand1(boolean isProcessBuilder, String command)
  5. executeCommand2(boolean isProcessBuilder, String command)
  6. executeCommandForceDir(String baseCommand, String osPath, File file)
  7. executeCommandLine(String command)
  8. executeCommandLineReturnAll( final String[] command)
  9. executeCommandLinux(final String _command)