Batch file writing to log then ending process

Posted by Andrew Service on Stack Overflow See other posts from Stack Overflow or by Andrew Service
Published on 2012-04-04T11:26:47Z Indexed on 2012/04/04 11:28 UTC
Read the original article Hit count: 194

Filed under:

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

© Stack Overflow or respective owner

Related posts about batch-file