import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created on 2004-5-23
* @author yuchifang
* 测试如何执行本地程序并捕获out和err输出
*/
public class TestInOutErr
{
public static void main(String[] args) throws IOException
{
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()));
while ((currentLine = err.readLine()) != null)
System.out.println(currentLine);
}
}
本文地址:http://com.8s8s.com/it/it16054.htm