Batch file writing to log then ending process
- by Andrew Service
I have a batch file that calls a process and in that process I have:
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
Now I wanted to upgrade this a bit and give some meaningful message to an output log when if the process fails, also I do not want the main batch to continue processing because the next processes are dependent on data from previous calls; I wonder if this would be correct but not sure:
CALL Process 1
IF %ERRORLEVEL% NEQ 0 GOTO ErrorInfirstProcess /B %ERRORLEVEL%
:ErrorInfirstProcess
ECHO Process 1 Failed on %Date% at %Time%. >>C:\Log.txt"
CALL Process 2
IF %ERRORLEVEL% NEQ 0 GOTO ErrorInSecondProcess /B %ERRORLEVEL%
:ErrorInSecondProcess
ECHO Process 2 Failed on %Date% at %Time%. >>C:\Log.txt"
I also want to know if I still need the /B or do I need to put an EXIT command after the echo?
Thanks
A