tags:

views:

75

answers:

1

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

Any ideas?

Thanks!

+3  A: 

You can redirect the results to a file:

C:\> myBatch.bat > myBatch.log

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

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

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

EDIT:

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:

@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
akf
Thanks! Can I add this inside my batch file? Or do I need to create another batch file to call this batch file and direct it to log?
joe
you can add it to all commands within your batch file. look at my edit for a bit more info.
akf