How to capture stderr on Windows/DOS?

可紊 提交于 2019-11-27 20:19:55

问题


I want to capture the errors from a script into a file instead of to the screen.

In *nix, this is done with stderr redirection, usually

echo "Error" 2> errorfile.log

How do I do it in a CMD script under Windows?


回答1:


For example:

PSKILL NOTEPAD >output.txt 2>&1

This will direct stdout and stderr to a file name output.txt.

See Underused features of Windows batch files for more details.




回答2:


That should work in Win32, too.

If you have already redirected stdout, and want stderr redirected to the same file, you must use the 2>& special form, rather than just specifying the same file twice. Otherwise you'll get a "file busy" error.



来源:https://stackoverflow.com/questions/482678/how-to-capture-stderr-on-windows-dos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!