简体   繁体   English

如何通过Java启动的不同进程重定向输出

[英]How to redirect output by a diffrent process initiated by java

I have a java program running on Linux machine. 我有一个在Linux机器上运行的Java程序。 It invokes an ant target to execute. 它调用一个ant目标来执行。 I can see the logs on the screen printed but there is no log file, which was produced when i used to run it using shell script. 我可以在屏幕上看到日志,但没有日志文件,这是我以前使用Shell脚本运行它时生成的。 I want to redirect the screen logs into a file. 我想将屏幕日志重定向到文件中。 I tried "tee" to redirect but it redirects only the part that i am printing in java class. 我尝试使用“ tee”重定向,但它仅重定向我在java类中打印的部分。 Can some one help me with this. 有人可以帮我弄这个吗。

Inside your build.xml file, you can start and stop recording to a log file: 在build.xml文件中,您可以开始和停止记录到日志文件:

<record name="file.log" action="start"/>
...
<record name="file.log" action="stop"/>

See the appropriate ant documentation for more details. 有关更多详细信息,请参见相应的ant文档

If you'd rather not edit the build.xml, it is probable that ant is using stderr rather than stdout. 如果您不想编辑build.xml,则可能是ant使用stderr而不是stdout。 Find out what shell you are using and look up how to redirect stdout to stderr. 找出正在使用的shell,并查看如何将stdout重定向到stderr。 For example, in bash, it would be ant 2>&1 | tee file.log 例如,在bash中,它将是ant 2>&1 | tee file.log ant 2>&1 | tee file.log . ant 2>&1 | tee file.log

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

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