BATCH SET unable to use divide operator
5,934
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 videos on Youtube
Author by
Gen1n
A render wrangler in an animation company based in India, trying to hone my skills in programming. Update: Associate Innovator in an Australian based consulting company.
Updated on September 18, 2022Comments
-
Gen1n over 1 year
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?
-
Christian over 10 yearsWhat means blank? For me, the script works.
-
Christian over 10 yearsHave you added a "Pause"? I have written the code in notepad++ and it works as bat-script.
-
martineau over 10 yearsWorks for me in a command prompt window.
-
BillR over 10 yearsFile testbat.bat
CD C:\DeleteLater
SET /A Div=216/3
ECHO /3 %Div% >> testbat.txt
File testbat.txt/3 72
-
BillR over 10 yearsSubstitute
SET Div >> testbat.txt
yieldsDiv=72
in testbat.txt -
Gen1n over 10 yearsUPDATE: It works in my friend's PC as well but as soon as I import the same script to my computer and run it, it doesn't work. We both share the same version of Windows and almost same config but it shouldn't matter.
-