【发布时间】:2011-05-10 17:56:42
【问题描述】:
我正在尝试从我的应用程序中的外部应用程序获取控制台输出。当我从我的代码中调用外部应用程序时,它会挂起以下消息:
正在配置日志记录...
从 C:\GPAT\log4j.cfg 配置 log4j
然后什么也没有发生。我通过互联网搜索,似乎它可能是线程问题。但我不能修改这个外部应用程序,我必须通过 log4j。我像这样阅读外部应用程序:
StringBuffer output = new StringBuffer();
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(GSATCommand);
BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));
System.out.println("Test running...");
String line = null;
while ((line = input.readLine()) != null) {
System.out.println(line); // Writes the test output to console
output.append(line); output.append("\n");
}
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
System.out.println("Test successfully executed");
} catch (Throwable t) {
t.printStackTrace();
}
感谢阅读。
【问题讨论】:
标签: java multithreading log4j