Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using errorlevel in a batch file to know if a program exited normally

Tags:

batch-file

We have a program that is occasionally crashing. The customer runs the program from a scheduled task. When the program is run with a certain parameter, the program runs as an interface engine, creating a file and then ftp'ing the file to another server for import by another program.

I was wondering if I might have the scheduled task instead run a batch file. The batch file would run the program and check errorlevel as the program exits. If errorlevel is not equal to zero, then batch file would run the program again. Does anyone see problem with my plan to use errorlevel in a batch file?

Here's an example of the batch file:

:start    
myPgm.exe intfc    
if errorlevel <> 0 then start
like image 368
user1787319 Avatar asked Oct 31 '12 03:10

user1787319


1 Answers

Your IF statement is wrong. It should read

if %errorlevel% neq 0 goto start

Or your script could read

:start
myPgm.exe intfc || goto start
like image 148
dbenham Avatar answered Sep 29 '22 13:09

dbenham