将Windows cmd stdout和stderr重定向到单个文件 [英] Redirect Windows cmd stdout and stderr to a single file
本文介绍了将Windows cmd stdout和stderr重定向到单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将 DOS 命令的所有输出(stdout + stderr)重定向到单个文件:
I'm trying to redirect all output (stdout + stderr) of a DOS command to a single file:
C:\>dir 1> a.txt 2> a.txt
The process cannot access the file because it is being used by another process.
有可能还是应该只重定向到两个单独的文件?
Is it possible, or should I just redirect to two separate files?
推荐答案
您要:
dir > a.txt 2>&1
语法2>&1
会将2
(stderr)重定向到1
(stdout).您还可以通过重定向到NUL
,
The syntax 2>&1
will redirect 2
(stderr) to 1
(stdout). You can also hide messages by redirecting to NUL
, more explanation and examples on MSDN.
这篇关于将Windows cmd stdout和stderr重定向到单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文