Appending output of a Batch file To log file

后端 未结 4 1318
暖寄归人
暖寄归人 2020-12-07 23:10

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 fi

4条回答
  •  甜味超标
    2020-12-07 23:41

    Instead of using ">" to redirect like this:

    java Foo > log
    

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

    java Foo >> log
    

    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 
    

提交回复
热议问题