Windows cmd stderr redirection to stdout while keeping output to stderr

redirectionstderrstdoutwindowswindows-command-prompt

Is there a way in Windows 7 cmd shell to redirect the stderr to stdout while keeping the stderr stream intact?

For example, I have a program that outputs to stderr and stdout the following message

TO STDOUT  
TO STDERR

I want to have two files stderr.txt and stdout.txt with the following content

stderr.txt
TO STDERR

stdout.txt
TO STDOUT
TO STDERR

Is this possible?

Best Answer

I think this is what you want:

dir a.txt > output.msg 2> output.err >&1

or

dir 1>a.txt 2>&1 | type a.txt

2> redirects stderr &1 sends stderr back to stderr.

I'd have to test these to give you a better answer