简体   繁体   中英

Batch file set /p expressions

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.

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%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM