Page 1 of 1

Change the value of errorlevel for testing purposes

Posted: 23 Jul 2019 08:18
by sacha99
Hello,
I need to change a line in some old scripts from this

Code: Select all

If Not ERRORLEVEL 0 (
to this

Code: Select all

IF %errorlevel% NEQ 0
Because of this change I need to test the scripts to make sure it doesn't change the output of the scripts. How can I set the errorlevel ? From my search on internet, it seems I cannot change it.

Thank you for your help.

Re: Change the value of errorlevel for testing purposes

Posted: 23 Jul 2019 13:08
by aGerman
Easiest way to set the errorlevel to a certain value:

Code: Select all

cmd /c exit 5
echo %errorlevel%
Steffen

Re: Change the value of errorlevel for testing purposes

Posted: 23 Jul 2019 13:47
by dbenham
sacha99 wrote:
23 Jul 2019 08:18
I need to change a line in some old scripts from this

Code: Select all

If Not ERRORLEVEL 0 (
to this

Code: Select all

IF %errorlevel% NEQ 0
In case you don't know, those two statements give entirely different results.

IF NOT ERRORLEVEL 0 only returns TRUE if ERRORLEVEL is less than 0. It returns FALSE if greater than or equal to 0.

IF %ERRORLEVEL% NEQ 0 returns TRUE if ERRORLEVEL is greater than 0 or less than 0. It only returns FALSE if exactly 0.


Dave Benham