How to copy stdout and stderr into a log file in Windows XP

command-line-interfacems-dospiperedirectwindows-xp

I have a script that I'm running from a command line. I want the stdout and stderr to be displayed on the screen and also to be copied into a logfile with append.

What is the syntax for this piping/redirection?

Best Answer

Give this a try:

for /f "delims=" %L in ('scriptname 2^>^&1') do @echo %L & echo %L >> log

The for command iterates over the output lines of the script. The carets escape the characters that follow them. The first echo goes to the screen and the second is appended to the file named "log".

Note that Powershell has the tee command.