Here you can find the source of executeCommand(String command)
public static String executeCommand(String command)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; public class Main { public static String executeCommand(String command) { return executeCommand(command, "./"); }/*w w w . ja v a 2 s . co m*/ public static String executeCommand(String[] command) { return executeCommand(command, "./"); } public static String executeCommand(String command, String path) { StringBuffer output = new StringBuffer(); Process p; try { p = Runtime.getRuntime().exec(command, null, new File(path)); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); } } catch (Exception e) { e.printStackTrace(); } return output.toString(); } public static String executeCommand(String[] command, String path) { StringBuffer output = new StringBuffer(); Process p; try { p = Runtime.getRuntime().exec(command, null, new File(path)); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = ""; while ((line = reader.readLine()) != null) { output.append(line + "\n"); } } catch (Exception e) { e.printStackTrace(); } return output.toString(); } }