Here you can find the source of exec(String... command)
public static String exec(String... command) throws IOException, InterruptedException
//package com.java2s; /*/*from www .j a v a 2 s .c o m*/ * Copyright (c) 2014 Peter Palaga. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String exec(String... command) throws IOException, InterruptedException { Process p = Runtime.getRuntime().exec(command); p.waitFor(); InputStream in = null; StringBuilder result; try { in = p.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line = null; result = new StringBuilder(); while ((line = reader.readLine()) != null) { result.append(line + "\n"); } } finally { if (in != null) { in.close(); } } return result.toString(); } }