Watch CMD output while saving it

Want to view the contents of the CMD window scroll past you whilst simultaneously recording those contents to a log file?

This is somewhat difficult to do despite being a very simple concept. Although there are several ways to achieve it, especially using Windows PowerShell, I was unable to find a truly “simple” way (one that doesn’t require scripting or programming knowledge). Part of the problem is that what you see in the CMD window output is the result of two streams (STDERR and STDOUT) which are not automatically merged together when exporting.

Assuming you are okay with downloading a 3rd party program and you do not absolutely need to see the output of the CMD script in a CMD window itself (instead using a CMD window emulator of sorts), read on.

The most painless way I could find to achieve the desired result was to combine three things:

  1. > or >> CMD option to output results to a file (> overwrites, >> appends)
  2. 2>&1 to combine the STDERR/STDOUT streams
  3. mTail.exe Windows Utility to emulate the Unix tail command

Here is a CMD script example (it runs a Python client for the CGOS server):

REM Open the 0.3 Python version of the Computer Go Server (CGOS) Client GTP Program
set CGOS_PATH=C:\Users\Ero-Sennin\Desktop\cgosClient\bin
set CGOS_CONFIG=cgos_fuego_9x9.cfg
%CGOS_CLIENT% %CGOS_CONFIG% >> cgos_full.log 2>&1

The Python script being executed will generate STDOUT and STDERR messages which will both be sent to the cgos_full.log file. These streams will NOT appear in the CMD window at all. Download and run the stand-alone program mTail.exe. Open up cgos_full.log within mTail.exe while the CMD script is executing. This will allow you to view in real-time the updates/progress of the log as though you were watching through the CMD window, and both the STDOUT and STDERR will be captured continuously.

Screenshot of CMD Logging with mTail Display

mTail in action alongside CMD Window

Superuser related link

Stack Overflow related link