[英]Capturing output from java
I'm trying to capture output from a java app but I'm missing something. 我正在尝试捕获Java应用程序的输出,但是缺少某些内容。 I'm using the following batch file:
我正在使用以下批处理文件:
@echo off
echo Start of batch
java makeQRCode
echo End of batch
If I run the batch file from a command prompt, I see the 3 lines I'm expecting. 如果我从命令提示符处运行批处理文件,则会看到3行。
Start of batch
Here is your java output.
End of batch
When I call the batch file using the following code, I only see the first and last lines but not the one in the middle. 当我使用以下代码调用批处理文件时,我只看到第一行和最后一行,而中间没有。
try{
Runtime rt = Runtime.getRuntime();
log.debug("Calling rt.exec...");
Process pr = rt.exec("c:\\adhoc\\java\\qrcode\\makeQRCode.bat");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line=null;
while((line=input.readLine()) != null) {
out.print(line);
log.debug(line);
}
input.close();
int exitVal = pr.waitFor();
}catch (Exception e){
log.error("Error generating qr code: " + e.toString());
}
Here's my log output when the above code is run: 这是运行上述代码时的日志输出:
2013-05-23 17:16:32,957 DEBUG _getimage - Start of batch
2013-05-23 17:16:33,126 DEBUG _getimage - End of batch
I think I'm missing something related to stdout but I've been playing with it for hours now and just can't get it right. 我想我缺少与stdout相关的东西,但是我已经玩了好几个小时了,只是无法正确使用。
Thanks 谢谢
There may be an issue either finding the java
binary or locating the makeQRCode
class. 查找
java
二进制文件或查找makeQRCode
类都可能存在问题。 Check the error stream of the Process
. 检查
Process
的错误流。
BufferedReader error = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String errorLine = null;
while ((errorLine = input.readLine()) != null) {
System.out.print(errorLine);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.