Need help to create log file for batch script installer

195 views Asked by At

I'm creating batch script for an software installer and i want to create a a log which contains all log for installation process. Can someone help me to create log file and to write all log in log file.

Thanks, Sameer

1

There are 1 answers

0
lit On

If you have a single install program writing to a single log file, it is pretty easy. If you have multiple programs all wanting to write to a single log file, that's a different story. Can you not use the Microsoft installer?

@ECHO OFF
SETLOCAL
SET EXITCODE=0
SET LOGFILE=C:\the\log\dir\the.log

REM The next line deletes any existing logfile.
IF EXIST "%LOGFILE%" (DEL "%LOGFILE%")

CALL:WriteToLog NB: This is a note.
CALL:WriteToLog ERROR: Something messed up.
SET EXITCODE=1

EXIT /B %EXITCODE%

:WriteToLog
ECHO>>"%LOGFILE%" %DATE% %TIME% %*
GOTO:EOF