Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { BufferedReader reader; public static String system(String evaluatedContents, String failedString) { Runtime rt = Runtime.getRuntime(); //System.out.println("System "+evaluatedContents); try { Process p = rt.exec(evaluatedContents); InputStream istrm = p.getInputStream(); InputStreamReader istrmrdr = new InputStreamReader(istrm); BufferedReader buffrdr = new BufferedReader(istrmrdr); String result = ""; String data = ""; while ((data = buffrdr.readLine()) != null) { result += data + "\n"; } //System.out.println("Result = "+result); return result; } catch (Exception ex) { ex.printStackTrace(); return failedString; } } public String readLine() { String result = null; try { result = reader.readLine(); } catch (IOException e) { System.err.println("error: " + e); } return result; } }