Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

cmd

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.

like image 424
joe Avatar asked Sep 22 '09 18:09

joe


People also ask

How do I show output in cmd?

In the command, change "YOUR-COMMAND" with your command and "c:\PATH\TO\FOLDER\OUTPUT. txt" with the path and file name to store the output. In the command, change "YOUR-COMMAND" with your command and "c:\PATH\TO\FOLDER\OUTPUT. txt" with the path and filename to store and view the output.

How do I export output from text to cmd?

Any command that has a command window output (no matter how big or small) can be appended with > filename. txt and the output will be saved to the specified text file.

Which command is placed in a batch file to display text on the screen?

Command echoing is on by default. Specifies the text to display on the screen.


1 Answers

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
like image 156
akf Avatar answered Oct 06 '22 00:10

akf