To identify any errors that may occur during the execution of a batch script, this article will demonstrate how to enable logging to an output file.

Command lines to log a batch script, if an error should occur:

call :Logit>>C:\batch.log 2>&1
:Logit

Example

To create a log file called “batch.log” in the C:\ directory.
Any lines of code after “:Logit” will be monitored for errors and outputted to the text file.

@ECHO OFF

call :Logit>>C:\batch.log 2>&1
:Logit

Rest of the script goes here…

exit /b

To learn how to log a MSI pacakge installation, click here.