MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Logging RollOver (keep [Next]: Maths
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Batch Files->Batch File Tips and Tricks->Logging Whole Batch File Execution

Logging Whole Batch File Execution

This is a simple approach which can can log the complete execution of a batch file. The batch file can use the "echo" command (I'd recommend outputting a prefix of "[%date% %time%]") to display progress information.

Some care and testing is required if long running programs are spawned (to ensure you can access the file. The batch below demonstrates a number of approaches to building a suitable log filename.

As written its assumed that no parameters are passed, but you could easily alter this to use an environment variable or any other flag. What it does is detect that its started and then restarts itself while redirecting the output making it a relatively trivial process to add good logging to any existing batch files while also being very handy for schedules etc.

The following demonstrates the process (just add to the front of the batch file):

@echo off
setlocal

@REM *** START: Turns logging on ***
if "%~1" == "NOWLOGGING" goto NowLogging
    set SchedulesLogFile=%TEMP%\%~n0 - %date:/=-% %time::=_%.txt
    set SchedulesLogFile=%TEMP%\%~n0 - %RANDOM%.txt
    set SchedulesLogFile=%TEMP%\%~n0.txt
    %0 "NOWLOGGING" > "%SchedulesLogFile%" 2>&1
    goto :EOF
:NowLogging
@REM *** END: Turns logging on ***


@rem Guts of batch file...
echo [%date% %time%] starting...
echo *** start of actual batch file...
...
echo *** end of actual batch file...
echo [%date% %time%] ending...


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Logging RollOver (keep [Next]: Maths


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Friday October 13 2017 at 2:08pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.