Using errorlevel in a batch file to find out if the program exited normally

We have a program that sometimes crashes. The client starts the program from the scheduled task. When a program starts with a specific parameter, the program starts as an interface engine, creating a file and then ftp'ing a file to another server for import by another program.

I was wondering if I could have a scheduled task instead of running a batch file. The errorlevel file launches the program and checks for errorlevel as the program exits. If errorlevel not zero, then the batch file will run the program again. Does anyone see a problem with my plan for using errorlevel in a batch file?

Here is an example batch file:

 :start myPgm.exe intfc if errorlevel <> 0 then start 
+7
source share
2 answers

I would write it like this:

 :start myPgm.exe intfc IF %errorlevel% NEQ 0 GOTO :error GOTO :end :error echo There was an error. EXIT 1 :end echo End. EXIT 0 
+9
source

Your IF statement is invalid. He must read

 if %errorlevel% neq 0 goto start 

Or your script can read

 :start myPgm.exe intfc || goto start 
+3
source

All Articles