Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 422 Vote(s) - 3.66 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is ERRORLEVEL reliable?

#1
Since ERRORLEVEL is an environment variable isn't it possible that its value can be changed before I get a chance to check it in my batch file?
Reply

#2
`%errorlevel%` (it is not really case sensitive) is a very special environment variable. It is not at all meant for setting by users or inside batch scripts.

Also, you may run into the problem that you execute the call `set errorlevel=15` but the very fact that you successfully executed the `set` command, may have reset the `%errorlevel%` you're expecting to now evaluete `0`.

Should you need it

The only *"legal"* way to evaluate the `%errorlevel%` environment variable is using repeated `if errorlevel` statements:

if errorlevel 0 do somecommand
if errorlevel 1 do somethingelse
...
if errorlevel 255 do lastalternative

everything else is dangerous. If you indeed need to use the current %errorlevel% a few lines later, then use something like

if errorlevel 0 do set myerrorlevel=0

and then readout `%myerrorlevel%`...
Reply

#3
Environment variables belong to the current "process" so they can't be changed from outside. Provided you check the error level after the relevant command in your batch file, you should be checking the right value.

You can confirm this by opening up two command windows and entering into the first:

c:> set errorlevel=7
and then the second:

c:> set errorlevel=9
then go back to the first and:

c:> echo %errorlevel%
7

You should be very careful about setting the `errorlevel` environment variable by the way. That particular variable is a special one in that, when you haven't set it specifically, it will automatically serve up the return code from the previous program.

Setting it explicitly overrides this behaviour, and the only way to recover is to either use `if errorlevel N`<sup>(a)</sup> instead of the environment variable (it bypasses the environment variable), or use `set errorlevel=` to remove the override.

---

<sup>(a)</sup> The correct way to do this is mandated by fact that the `errorlevel` expression is true if the error level is *greater than or equal to* the value specified. Because of that, you should do it in reverse order, something like:

if errorlevel 3 goto :got3ormore
if errorlevel 2 goto :got2
if errorlevel 1 goto :got1
if errorlevel 0 goto :got0
goto :gotnegative
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through