Displaying Windows command prompt output and redirecting it to a file
How can I run a command-line application in the Windows command prompt and have the output both displayed and redirected to a file at the same time?
If, for example, I were to run the command dir > test.txt
, this would redirect output to a file called test.txt
without displaying the results.
How could I write a command to display the output and redirect output to a file in the Windows command prompt, similar to the tee
command on Unix?
Solution 1:
To expand on davor's answer, you can use PowerShell like this:
powershell "dir | tee test.txt"
If you're trying to redirect the output of an exe in the current directory, you need to use .\
on the filename, eg:
powershell ".\something.exe | tee test.txt"
Solution 2:
I was able to find a solution/workaround of redirecting output to a file and then to the console:
dir > a.txt | type a.txt
where dir is the command which output needs to be redirected, a.txt a file where to store output.
Solution 3:
There's a Win32 port of the Unix tee
command, that does exactly that. See http://unxutils.sourceforge.net/ or http://getgnuwin32.sourceforge.net/