How to perform local programs in Java and capture OUT and ERR output

xiaoxiao2021-03-06  103

In the past few days, the virus was broken, and the JCREATOR didn't use the batch to the students. I would like to write a simple point to write a simple point. I finally know how to capture the output. The semester is over:

Import java.io.bufferedreader; import java.io ioException; import java.io.inputstreamReader;

/ *** CREATED ON 2004-5-23 * @Author Yuchifang * Test how to perform local programs and capture OUT and ERR output * / public class testinouterr {public static void main (string [] args) throws oews oewception {process p = runtime .getRuntime () exec ( "java test");. BufferedReader in = new BufferedReader (new InputStreamReader (p.getInputStream ())); String currentLine = null; while (! (currentLine = in.readLine ()) = null) System.out.println (currentLine); BufferedReader err = new BufferedReader (new InputStreamReader (p.getErrorStream ())); (! (currentLine = err.readLine ()) = null) while System.out.println (currentLine); }

转载请注明原文地址:https://www.9cbs.com/read-124936.html

New Post(0)