Here you can find the source of exec(String cmd)
public static String exec(String cmd)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.ArrayList; import java.util.List; public class Main { public static String exec(String cmd) { Process process = null;/*from w w w .j av a2 s. co m*/ List<String> processList = new ArrayList<String>(); try { process = Runtime.getRuntime().exec(cmd); BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = ""; while ((line = input.readLine()) != null) { processList.add(line); } input.close(); return processList.get(0); } catch (IOException e) { System.out.println("error"); e.printStackTrace(); return "error"; } } }