Sign in with
Sign up | Sign in
Your question

Batch File Error Trapping

Last response: in Windows XP
August 30, 2011 11:36:40 AM

I have several batch files that are ran through Scheduled Tasks. The files do things such as making copies of files and running macros. I need a way to know if an event does not get carried out. If anyone could tell me how I would go about adding some error trapping where it could write it to a text file, I'd appreciate it.
August 30, 2011 3:28:13 PM

You'd need to know what error codes come up when something executes.

Will be like: if [not] errorlevel number command [else expression]

errorlevel number : Specifies a true condition only if the previous program run by Cmd.exe returned an exit code equal to or greater than number.

From here:

August 30, 2011 6:07:18 PM

=> 0
he just want to know if the event carried out
August 30, 2011 10:01:20 PM

Most executables will report 0 as ERRORLEVEL if everything went good and some higher numbers for different errors. Perhaps in your case you could try with some line like this after each COPY for example:

IF NOT "%ERRORLEVEL%"=="0" ECHO Copy error. >> C:\your-log-file.txt