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

I want to execute a batch file and call it 10 times.

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

However, before error with

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

in line

 set /a iteration=0%1+1 

How can I fix this error?

+4
source share
2 answers

You have 0%1 in this expression - if your argument is 8, which extends to 08 , which is not a real octal number (8 is not an octal digit), and therefore you get this error, I am not an expert on a batch file, but I think you want to leave a leading 0 :

 set /a iteration=%1+1 

Here is a link to some documentation of the SET command .

+6
source

As Carl said, the leading zero is the sign of octal numbers. Sometimes a leading zero seems useful, since you avoid the error if %1 empty.

But then you have problems that can be solved using a slightly different method.

Turning 1 or better 100 , and then building the module will also work with numbers 8 and 9 (as well as empty input).

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

But in your case, deleting zero should be enough, even if %1 empty, you got the correct expression.

 set /a iteration=%1 + 1 

Will expand to set /a iteration= + 1

+4
source

Source: https://habr.com/ru/post/1402145/


All Articles