关于Window的Dos Batch 文件编写的常识

时间:2014-08-05 14:30:10   收藏:0   阅读:296

Redirect "all" output to a single file:

Run:

test.bat > test.txt 2>&1

and you‘ll get this text on screen (we‘ll never get rid of this line on screen, as it is sent to the Console and cannot be redirected):

This text goes to the Console

You should also get a file named test.txt with the following content:

This text goes to Standard Output
This text goes to Standard Error

Note: The commands
                test.bat  > test.txt 2>&1
                test.bat 1> test.txt 2>&1
            test.bat 2> test.txt 1>&2
all give identical results.


Redirect errors to a separate error log file:

Run:

test.bat > testlog.txt 2> testerrors.txt

and you‘ll get this text on screen (we‘ll never get rid of this line on screen, as it is sent to the Console and cannot be redirected):

This text goes to the Console

You should also get a file named testlog.txt with the following content:

This text goes to Standard Output

and another file named testerrors.txt with the following content:

This text goes to Standard Error


Some "best practices" when using redirection in batch files:



关于Window的Dos Batch 文件编写的常识,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!