• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2332
  • Last Modified:

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?
0
deathbybatfile
Asked:
deathbybatfile
  • 3
  • 2
1 Solution
 
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
 
joshlunsfordCommented:
Would have to be

if not %ERRORLEVEL% == 1 echo blah


variable in batch need percent signs at the beginning and end
0
 
deathbybatfileAuthor Commented:
That's great - thanks Josh
0
 
deathbybatfileAuthor Commented:
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now