Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know cmd > file.txt to record an output of a command to a file in Windows!.

Does anybody know how to run a batch script recording the output to a file AND also showing the output on the command prompt as well when executed?

share|improve this question
up vote 3 down vote accepted

You'll need a Windows-based implementation of tee to do this. Here are some options:

If you don't require output in situ, you can "cheat" by piping the commands, but this is not nearly as useful as following stdout in real-time.

cmd >file.txt | type file.txt

share|improve this answer
I thought of using your easy method cmd >file.txt | type file.txt but it's showing the copy percentage as 0%(not updating) till the end. I'm trying to install wintee, didn't get correct link yet. Trying... – user53864 Jul 23 '11 at 5:58
@user53864 Yes, the redirection+pipe doesn't work quite like tee, as the first command must complete entirely before the type will occur. The link in my answer is a working version of wintee -- is it non-functional for you? – jscott Jul 23 '11 at 10:38
That wintee.exe just opening and staying like a statue when I double clicked to execute it. – user53864 Jul 23 '11 at 12:40
@user53864 It is a command-line program, not a windowed one. Try wtee.exe --help for usage. Using your question's example, you'd want to do cmd | wtee.exe file.txt to see the output on stdout as well as redirect it to file.txt. – jscott Jul 23 '11 at 12:47 Actually I was using cmd | tee file.txt instead of cmd | wtee file.txt. That was my mistake which you corrected it. I thought I should install wtee.exe file by double clicking it but as you said it's not and instead should directly place it under system32. Thanks a lot!! – user53864 Jul 23 '11 at 15:44

How about mtee?


This looks most appealing to me...

script.cmd | mtee result.%date:~-4,4%%date:~-10,2%%date:~-7,2%.log

The result log will have YYYYMMDD format.

If you want to include time with the log, you can also include this:

%time:~0,2%%time:~3,2% (HHmm)

p.s. I just noticed that if the time is AM there is a space in the file name, so you will need to wrap mtee log file in double quotes to generate the correct file name.

share|improve this answer

Your Answer


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.