Solved Set outputs Missing operand for no apparent reason.

Various brands / CUSTOM BUILT
May 19, 2015 at 14:10:21
Specs: Windows 7 Professional x64, 3.6GHz 16GB
Working on a script that reads some file names from a .txt list.
The user can issue a "reload" command to reload the names.

when reloading, the script gets the old name count:

echo !counter!>c.tmp
for /f "tokens=1" %%A in (c.tmp) do set oCount=%%A
del /q c.tmp
set rel=1
goto restart

Then after reloading the name list, it runs this to determine if any names has been removed or added:

set add=-1
set /a _a1=!counter!-!oCount!
if !_a1! LSS 0 set _b1=!_a1:-=! && set add=1
if !_a1! GTR 0 set add=0
set _b1=!_b1: =!
if !add!==0 Echo !_b1! command^(s^) unloaded. && goto cont
if !add!==1 Echo !_b1! new command^(s^) loaded. && goto cont
if !add!==-1 Echo No commands changed. && goto cont

However, in this part, it outputs "missing operand".

How can I fix this?

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ

See More: Set outputs Missing operand for no apparent reason.

Report •

May 19, 2015 at 21:46:45
✔ Best Answer
Well, since SET /A is the only operation that generates this error, that narrows it down. Apparently !counter! has not been defined prior to the SET /A operation. You can test this easily with ECHO {{!counter!}}, or by assigning a value to counter imm prior to the SET /A then see if the error goes away.

Report •

May 20, 2015 at 03:36:27
I suggest to prefix a redirector with a space since a numerical value may lead to unpredictable results. So replace

echo !counter!>c.\tmp with echo.!counter! > c.\tmp

Stdout must be 1 to save the echo output to c.tmp and the value of !counter! forces another source. There are other things in your script I don't like, but now I am short on time.

Report •

Related Solutions

Ask Question