CSDN博客

img fanrey

如何执行本地程序并捕获out和err输出(written in Java)

发表于2004/10/12 11:21:00  858人阅读

分类: 转载区

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TestInOutErr
{
  public static void main(String[] args) throws IOException
  {
    Process p = Runtime.getRuntime().exec("java AppTest");
    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);
  }
}

阅读全文
0 0

相关文章推荐

img
取 消
img