DOS - How to echo to both the console and a file

Using DOS alone, you can't.

You will need to use Tee, a utility designed to solve this exact problem.

Console
File
dir
Yes
Output to: Console only
dir > file.txt
Yes
Output to: File only
dir | tee file.txt
Yes
Yes
Output to: Console & File
dir 2>&1 | tee file.txt
Yes
Yes
Output to: Console & File, including standard error

Tee will write to the console and the filename passed as a parameter.

Think of a highway T-junction or a plumber's T-splitter. A T has 1 input and 2 outputs.


tee --help
Usage: tee [OPTIONS] [FILE]
Copy standard input to standard output and FILE.

Where can I find tee for Windows ?


Ads by Google


Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath