Using Errorlevel 0 in a batch file

I am looking at a simple couple of lines that will cause my program to run until it is successfully completed.
I am thinking of using the following within my code:

IF EXIST C:\Progra~1\Player\settingschanged.dat GOTO END

(REST OF CODE DOES IT'S TASKS THEN SENDS TO REBOOT LABEL)

:REBOOT

IF ERRORLEVEL=0 ECHO Settings changed>C:\Progra~1\Player\settingschanged.dat

shutdown -r -f -t 0

:END
EXIT

Thus will run until all done correctly and then file will exist so stop it from running?
deathbybatfileAsked:
Who is Participating?
 
joshlunsfordConnect With a Mentor Commented:
Would have to be

if not %ERRORLEVEL% == 1 echo blah


variable in batch need percent signs at the beginning and end
0
 
joshlunsfordCommented:
Code for checking  the variable errorcode would be
if %ERRORLEVEL% == 1 echo Settings changed>C:\Progra~ \Player\settingschanged.dat

Open in new window

0
 
deathbybatfileAuthor Commented:
Thanks Josh.

Would it work as:

IF NOT ERRORLEVEL=1 ECHO.....etc
or would it have to be:
IF NOT %ERRORLEVEL=1 ECHO....etc

This last just for my curiosity really - thanks for the response. :D
0
 
deathbybatfileAuthor Commented:
That's great - thanks Josh
0
 
deathbybatfileAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.