Here you can find the source of exec(String cmd)
public static String[] exec(String cmd) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static String[] exec(String cmd) throws Exception { Process p = Runtime.getRuntime().exec(cmd); p.waitFor();/*from w w w . ja v a 2s. com*/ BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); String s = null; StringBuilder sbout = new StringBuilder(); while ((s = stdInput.readLine()) != null) { sbout.append(s); } StringBuilder sberr = new StringBuilder(); BufferedReader stdErrIn = new BufferedReader(new InputStreamReader(p.getErrorStream())); while ((s = stdErrIn.readLine()) != null) { sberr.append(s); } String[] ret = new String[2]; ret[0] = sbout.toString(); ret[1] = sberr.toString(); return ret; } }