简体   繁体   English

将System.err.println的输出重定向到一个文件,而无需更改代码

[英]Redirect the output of System.err.println to a file without code change

I have an existing jar file that contains a class I am execution from a batch file as shown below. 我有一个现有的jar文件,其中包含正在从批处理文件执行的类,如下所示。

java -classpath %CLASSPATH% com.xxx >> LOG_FILE_name 

The class contains lot of System.out and System.err. 该类包含许多System.out和System.err。 The System.out is going to the log file mentioned as redirection but the error message is still coming to the console. System.out将转到作为重定向提到的日志文件,但错误消息仍在控制台中。

How can I redirect System.err to the same log file? 如何将System.err重定向到同一日志文件? I am not in a position to change the code of the classes in the jar file. 我无法更改jar文件中类的代码。

You redirect stderr, like 您重定向标准错误,例如

java -classpath %CLASSPATH% com.xxx >> LOG_FILE_name 2>> ERR_LOG_FILE_name java -classpath%CLASSPATH%com.xxx >> LOG_FILE_name 2 >> ERR_LOG_FILE_name

To use the same log file that would be 要使用相同的日志文件

java -classpath %CLASSPATH% com.xxx >> LOG_FILE_name 2>&1 java -classpath%CLASSPATH%com.xxx >> LOG_FILE_name 2>&1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM