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.*; public class Main { public static String executeCommand(String command) { try {/* w ww . jav a 2 s .c om*/ Runtime r = Runtime.getRuntime(); String[] cmd = { "/bin/sh", "-c", command }; Process p = r.exec(cmd); p.waitFor(); return inputStreamToString(p.getInputStream()); } catch (IOException ex) { return ex.toString(); } catch (InterruptedException ex) { return ex.toString(); } } public static String inputStreamToString(InputStream inputStream) { BufferedReader b = new BufferedReader(new InputStreamReader(inputStream)); String line; StringBuilder all = new StringBuilder(); try { while ((line = b.readLine()) != null) { all.append(line); } } catch (IOException e) { return e.toString(); } return all.toString(); } }