将批处理文件的输出追加到日志文件 [英] Appending output of a Batch file To log file

查看:692
本文介绍了将批处理文件的输出追加到日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调用Java程序的批处理文件.

I have a batch file which calls a java program.

将输出重定向到同一目录中的日志文件. 但是,每次运行批处理文件时,日志文件都会被替换...

The output is redirected to a log file in the same directory. However the log file is replaced everytime the batch file is run...

我想将旧的输出保留在日志文件中,并始终将新的输出附加到日志文件中.

I would like to keep the old outputs in the log file and always append the new output to the log file.

推荐答案

而不是使用>"这样的重定向:

Instead of using ">" to redirect like this:

java Foo > log

使用">>"将普通的"stdout"输出附加到新文件或现有文件中:

use ">>" to append normal "stdout" output to a new or existing file:

java Foo >> log

但是,如果您还想捕获"stderr"错误(例如为什么无法启动Java程序),则还应该使用"2>& 1"标记来重定向"stderr"("2")到"stdout"("1").例如:

However, if you also want to capture "stderr" errors (such as why the Java program couldn't be started), you should also use the "2>&1" tag which redirects "stderr" (the "2") to "stdout" (the "1"). For example:

java Foo >> log 2>&1 

这篇关于将批处理文件的输出追加到日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆