2

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?

2 Answers 2

2

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

2
  • The first is not working. The second redirects stderr to stdout but does not give stderr alone.
    – Stecy
    Jul 20, 2012 at 15:48
  • may need to use a tee clone. The tricky part is that you want 2 copies of stderr. Pity you are stuck in the legacy prompt.
    – Jim B
    Jul 20, 2012 at 17:12
0

This is kludgy, but it works. clip.exe comes with modern versions of Windows and you can download it's counterpart - paste.exe - from several sources.

This line assumes that the file yyz.pdq does not exist and will therefore produce a "File Not Found" message to stderr:

(dir yyz.pdq 3>&1 1>&2 2>&3) | clip & paste >con & paste >err.txt

This form of the command will redirect to separate files for stderr and stdout+stderr, as originally requested:

((dir yyz.pdq 3>&1 1>&2 2>&3) | clip & paste & paste >err.txt) 1>out.txt 2>&1

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .