Invalid number. Numeric constants are either decimal (17), hexadecimal (0x11), or octal (021)

前端 未结 2 1968
情话喂你
情话喂你 2021-01-19 00:18

I wish to execute a batch file and have it call itself 10 times.

set /a iteration=0%1+1
IF %iteration% EQU 10 exit
rem Taskkill /IM aspnet_compiler.exe /F
ti         


        
2条回答
  •  [愿得一人]
    2021-01-19 01:05

    As Carl said, the leading zero is the sign for octal numbers.
    Sometimes a leading zero seems to be useful, as you would avoid an error in case %1 is empty.

    But then you got this type of problems, which can be solved by using a little bit other way.

    Prepending a 1 or better 100 and then building the modulo will also work with the numbers 8 and 9 (and also empty input).

    set /a iteration=1000%1 %% 100 + 1
    

    But in your case it removing the zero should be enough, even if %1 is empty you got a valid expression.

    set /a iteration=%1 + 1
    

    Would expand to set /a iteration= + 1

提交回复
热议问题