How to log text displayed in a Windows XP command line application

cmd

Solution

You can redirect the results to a file:

C:\> myBatch.bat > myBatch.log

The above will redirect standard output to a file called `myBatch.log`.

If you need to redirect standard error to this file as well, you can append `2>&1` to the command:

C:\> myBatch.bat > myBatch.log 2>&1

Note that the single `>` will overwrite a file and start from scratch and `>>` will append the captured output to the end of the file. You should be careful when using this syntax in a set of consecutive commands to use `>` on the first call to start a file, and then `>>` on all subsequent calls to add to the end of the new file.

For example, a simple bat file,

@echo off
echo start > test.log
date /t >> test.log
time /t >> test.log
echo done >> test.log

will generate a file named `test.log` filled with the following content:

start
Tue 09/22/2009
03:10 PM
done

Problem

Is there a simple way to log everything that appears on the command line on Windows? I have a batch file that is running some things, but everything flies by so fast I cannot see if any errors have occurred.

Original source