Displaying Windows command prompt output and redirecting it to a file

Ammu picture Ammu · Apr 28, 2009 · Viewed 485.1k times · Source

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?

Answer

Saxon Druce picture Saxon Druce · Dec 31, 2013

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"