Here you can find the source of execLocalhostCmd(String cmd)
public static String execLocalhostCmd(String cmd) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static String execLocalhostCmd(String cmd) throws IOException { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(cmd); InputStream is = proc.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader bufReader = new BufferedReader(isr); String line = ""; StringBuffer sbuf = new StringBuffer(""); while ((line = bufReader.readLine()) != null) { sbuf.append(line);/* w w w . j av a2 s.co m*/ } try { if (proc.waitFor() != 0) { //System.err.println("Exit Value = " + proc.exitValue()); } } catch (InterruptedException e) { System.err.println(e); } return sbuf.toString(); } }