Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.