Batch File Error Trapping

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.
3 answers Last reply
More about batch file error trapping
  1. 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:
  2. => 0
    he just want to know if the event carried out
  3. 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
Ask a new question

Read More

Macros Windows XP