Reputation:
I'm attempting to make the errorlevel environment variable increase by one every time a certain section of my code is ran. I read in set /? that you can use /p to list an expression that needs to be calculated after the equals sign, however it doesn't seem to change the errorlevel at all.
This is what I have.
if not %cd2%==%cd1% (goto :installauto) else set /p errorlevel=(%errorlevel%+1)
Thanks for the help, and sorry if this is a noob question. >.<
EDIT: Wow, I'm an idiot. The /a tag is used for expressions. Sorry lol.
Upvotes: 1
Views: 1548
Reputation: 82410
It's a bad idea to change/create an errorlevel variable, as this is not the errorlevel for other programs.
Then you can not access the "real" errorlevel anymore.
You could better do this with an other variable and exit the bacth file with exit /B
set myErr=0
if not %cd2%==%cd1% (
goto :installauto
) else (
set /a myErr=myErr+1
)
exit /b %myErr%
Upvotes: 1