Java tutorial
//package com.java2s; import java.io.DataInputStream; public class Main { public static String execCmd(String cmd) { String result = ""; DataInputStream dis = null; try { Process p = Runtime.getRuntime().exec(cmd); dis = new DataInputStream(p.getInputStream()); String line = null; while ((line = dis.readLine()) != null) { line += "\n"; result += line; } p.waitFor(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return result; } }