java中如何执行本地程序并捕获out和err输出
前些天机房中了病毒,jcreator坏了,editplus也用不起来那时只好用批处理给学生上课,想自己写个简单点的编译方式终于知道如何捕获输出了,学期也结束了:

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);
  }
}

相关文章:

  • 2021-11-15
  • 2021-12-24
  • 2022-12-23
  • 2021-07-31
  • 2021-09-28
  • 2022-02-11
猜你喜欢
  • 2021-05-21
  • 2021-12-21
  • 2021-07-17
  • 2021-09-02
  • 2022-12-23
  • 2022-01-24
相关资源
相似解决方案