Here you can find the source of exec(String... _command)
public static final String exec(String... _command) throws IOException, InterruptedException
//package com.java2s; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringWriter; import java.io.Writer; public class Main { public static final String exec(String... _command) throws IOException, InterruptedException { final ProcessBuilder pb = new ProcessBuilder(_command); final Process p = pb.start(); p.waitFor();/*from w w w . j a v a 2 s.c om*/ final StringWriter writer = new StringWriter(); writeStream(p.getInputStream(), writer); return writer.toString(); } private static final void writeStream(InputStream _from, Writer _printTo) throws IOException { final Reader in = new BufferedReader(new InputStreamReader(new BufferedInputStream(_from))); while (in.ready()) _printTo.write(in.read()); } }