/*****************************************************************/ /* Copyright 2013 Code Strategies */ /* This code may be freely used and distributed in any project. */ /* However, please do not remove this credit if you publish this */ /* code in paper or electronic form, such as on a web site. */ /*****************************************************************/ package test; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class RuntimeExecTest2 { public static void main(String[] args) { try { Runtime runTime = Runtime.getRuntime(); Process process = runTime.exec("java -classpath C:\\projects\\workspace\\testing\\bin test.TestOutput"); InputStream inputStream = process.getInputStream(); InputStreamReader isr = new InputStreamReader(inputStream); InputStream errorStream = process.getErrorStream(); InputStreamReader esr = new InputStreamReader(errorStream); int n1; char[] c1 = new char[1024]; StringBuffer standardOutput = new StringBuffer(); while ((n1 = isr.read(c1)) > 0) { standardOutput.append(c1, 0, n1); } System.out.println("Standard Output: " + standardOutput.toString()); int n2; char[] c2 = new char[1024]; StringBuffer standardError = new StringBuffer(); while ((n2 = esr.read(c2)) > 0) { standardError.append(c2, 0, n2); } System.out.println("Standard Error: " + standardError.toString()); } catch (IOException e) { e.printStackTrace(); } } }