How to redirect output to a text file and the console (cmd) window at the same time?

34,357

Solution 1

Powershell 2.0 comes with the Tee-Object cmdlet which does exactly that. If you're using Windows 7, it comes with Powershell 2.0 installed. If you're using an older version of Windows, Powershell 2.0 is available for download.

The benefit of Powershell is that it can run the commands that cmd can as well.

Example:

dir | Tee-Object -file c:\output\dir.txt

Solution 2

There's a good answer for an identical question on StackOverflow

In summary, find a Win32 port of the Unix tee command.

Share:
34,357

Related videos on Youtube

Thomas Bratt
Author by

Thomas Bratt

Working on configuration, control and reporting backend for a fintech / machine learning startup based in Cambridge. Using Java 8, Apache Kafka, Apache Zookeeper, Elasticsearch, MongoDB, Oracle 12c. Previously: using C#, NServiceBus, ASP.NET MVC, MS SQL Server and Oracle 11g databases developing management and control software in C#, C++, C for high bandwidth video over ATM and IP networks embedded work with C / Motorola 68000

Updated on September 17, 2022

Comments

  • Thomas Bratt
    Thomas Bratt over 1 year

    How can I redirect output to a text file and the console (cmd) window at the same time?

  • I say Reinstate Monica
    I say Reinstate Monica over 4 years
    Welcome. This question is about the Command Prompt (CMD) not PowerShell.