1.

Solve : Creating Log file?

Answer»

Anybody can help plz to find the way to CREATE a log file while I am runnning a batch file, ie all the steps performed and messages shown by RUNNING the batch file to be COPIED in a logfile.
Thanks in advance.
Hi Prince748,

You can do this by adding "debug statements" to your batch file. Here is an example of a batch file which contains four debug statements:

Code: [Select]@echo off
if exist log del log
echo Batch file started >>log
echo First parameter is "%1" >>log
echo Second parameter is "%2" >>log
echo Batch file finished >>log

Note that this batch file also contains a statement to delete the log from the previous run, if it exists.

Here is an example of running this on Windows XP:

Code: [Select]D:\test> TEST.BAT 111111

D:\test> TYPE LOG
Batch file started
First parameter is "111111"
Second parameter is ""
Batch file finished

D:\test>

Hope that helps,
James

Thanks. Actually what I wanted - if echo is not off, all the lines and action of the batch file shows on the screen. I WANT those lines to be written to a log file. What command might help?You need to redirect the output of the command processor; call your batch like this :

>> LogFileName cmd /c MyBatchFile.Bat

This will append to the contents of the logfile, if you want to create it anew each time, just USE >
Graham



Discussion

No Comment Found