0

How do you increment with Windows Batch?

set list=A B C D
set /a "port=1010"

for %%a in (%list%) do (
   echo %%a
   call :increaseby1
   echo %port%
)
:increaseby1
set /a "port+=1"

My main goal here is to iterate over all list and call another batch file like this:

for each list

dev_appserver.cmd -p [PORT+1] "A"

So this other batch would be called four times because the list is A B C and D.

quarks
  • 33,478
  • 73
  • 290
  • 513
  • 4
    You need to use delayed expansion. It is probably the number one problem people have with batch files and we see this issue daily on SO. Enable delayed expansion with the `SETLOCAL` command and then reference your variables with exclamation points. `echo !port!` – Squashman Apr 16 '18 at 15:51
  • 3
    You should use [delayed expansion](https://ss64.com/nt/delayedexpansion.html).And if you use the subroutine only for the incrementation may you should remove it.And you need `exit` r `goto :eof` before the subroutine label to avoid unwanted execution. – npocmaka Apr 16 '18 at 15:51
  • 2
    An alternative but slower solution: `call echo %%port%%` – aschipfl Apr 16 '18 at 16:28

0 Answers0