1

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?

1 Answers1

2

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.

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
  • I was really looking for something a lot more simple than this. Maybe I shouldn't have used the word "script". It's a java application that's creating all the output. So I only need do this for the output of one line. – Erick Robertson Jan 18 '11 at 18:26
  • @Erick: Can you do it within your java application? If not, then what I posted is probably all CMD is capable of. Your other option is to download one of the `tee` for Windows implementations. – Dennis Williamson Jan 18 '11 at 18:32