Here you can find the source of execute(String cmd, String input)
public static String[] execute(String cmd, String input)
//package com.java2s; import java.io.*; import java.util.*; public class Main { public static String[] execute(String cmd, String input) { System.out.println("--> " + cmd); ArrayList output = new ArrayList(); Runtime runtime = Runtime.getRuntime(); try {/*ww w . j a va2 s . com*/ Process process = runtime.exec(cmd); if (input != null) { OutputStream os = process.getOutputStream(); OutputStreamWriter osr = new OutputStreamWriter(os); BufferedWriter bw = new BufferedWriter(osr); bw.write(input); bw.close(); } InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { output.add(line); } } catch (Exception ex) { System.out.println(ex); } String output_array[] = new String[output.size()]; output.toArray(output_array); return output_array; } }