How to create log file from batch files

Many times we can do our tasks in batch mode. I personally like this approach and I use it alot in
my daily office work. In this post we will learn a very simple but very usefull trick to make our
batch files more usefull.

I have 3 batch files which have some operation in them (anything)

I want to execute these batch files in one go and want to create a log file for actions happened inside the batch file.


1. Open ‘Notepad’ and create a new file. save this file as “Main,cmd” (you can choose nay name you like )
2. Create a variable which contains our Logfile name.
3. Copy an d paste below mntioned lines in this file and save it .

@echo off
 REM Create a logfile name variable
 ECHO This is first log line >> %LOGFILE%
 ECHO Calling first file ‘file1.cmd’ >> %LOGFILE%
 REM file1.cmd >> %LOGFILE%
 ECHO Calling file ‘file2.cmd’ >> %LOGFILE%
 REM file2.cmd >> %LOGFILE%
 ECHO Calling file ‘file3.cmd’ >> %LOGFILE%
 REM file3.cmd >> %LOGFILE%
 ECHO Task completed >> %LOGFILE%

4. Run this file by double click on it .
Voilaa now you have new log file.

Note : If you have “Trace32” log viewer you can directly lauch it loaded with your log file

START trace32.exe %LOGFILE%


3 thoughts on “How to create log file from batch files

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s