Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

batch-file

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
timeout 1
call KillBILLd.bat %iteration%

However, it will only get to the number 8 before erroring with

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

on line

set /a iteration=0%1+1

How can I fix this error?

like image 426
Valamas Avatar asked Mar 18 '12 22:03

Valamas


2 Answers

You've got 0%1 in that expression - if your argument is 8, that expands to 08, which isn't a valid octal number (8 is not an octal digit), and so you get that error. I'm not a batch file expert, but I guess you want to leave off the leading 0:

set /a iteration=%1+1

Here's a link to some SET command documentation.

like image 154
Carl Norum Avatar answered Nov 15 '22 13:11

Carl Norum


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

like image 23
jeb Avatar answered Nov 15 '22 12:11

jeb