Here you can find the source of executeCommandAndExtractStdOut(String cmd)
public static String executeCommandAndExtractStdOut(String cmd) throws IOException, InterruptedException
//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(); } }