Here you can find the source of exec(String command)
public static String exec(String command)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; public class Main { public static String exec(String command) { try {/*from ww w . ja v a 2 s. com*/ Process process = Runtime.getRuntime().exec(command); InputStream errorStream = process.getErrorStream(); byte[] buffer = new byte[1024]; int readBytes; StringBuilder stringBuilder = new StringBuilder(); while ((readBytes = errorStream.read(buffer)) > 0) { stringBuilder.append(new String(buffer, 0, readBytes)); } return stringBuilder.toString(); } catch (IOException e) { e.printStackTrace(); } return null; } }