Is it possible to redirect output to multiple devices/files?

program.exe 1> output1.txt 1>output2.txt

This only produces output2.txt in Windows.

link|improve this question

50% accept rate
feedback

2 Answers

tee is a command that offers you the flexibility on *nix machines to redirect output to multiple files.

From the man page -

DESCRIPTION
     The tee utility copies standard input to standard output, 
making a copy in zero or more files.  The output is unbuffered.

On Windows, you can use something similar to this.

link|improve this answer
feedback

If you're using a Unix/Linux shell, or Cygwin on Windows, you can use tee to copy stdin to multiple output files:

program.exe | tee output1.txt >output2.txt

Not sure if there's a tee equivalent in native Windows cmd.exe.

Most shells, such as bash, let you combine stdout and stderr. Here's the syntax to merge stdout and stderr from program.exe and pipe it into tee. 2>&1 says to redirect the output of file descriptor 2 (stderr) to file descriptor 1 (stdout)

program.exe 2>&1 | tee output1.txt >output2.txt
link|improve this answer
Help says it will only copy standard stream. Is it possible to copy stderr stream with tee? – ShyMan Nov 29 '11 at 3:24
Yes it's possible. I added stderr to the example. – gordoco Nov 29 '11 at 12:58
feedback

Your Answer

 
or
required, but never shown

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