BATCH SET unable to use divide operator

batchbatch file

I am unable to divide using the divide operator provided in the SET command.

SET /A 216/18

SET /A div=216/18

ECHO %div%

Though this should work and it does in the command prompt window but when used through a batch script it gives a blank output.

like

ECHO is on.

Whats wrong?

Best Answer

This can happen if your extenstions are disabled. You can check setlocal /? and cmd /? for more information about extensions.

But the set /? specifies:

If Command Extensions are enabled SET changes as follows:  
...
Two new switches have been added to the SET command:  
  SET /A expression  
  SET /P variable=[promptString]

So without extensions the /A does not work.

You can add the setlocal-line to the top of your batchfile:

setlocal enableextensions enabledelayedexpansion
SET /A 216/18
SET /A div=216/18
ECHO %div%
Related Question