0

I want to use loop variables in windows cmd. However, the values showing are not correct.

I tried to add quotes/remove quotes, although the results are different, all of them are not working.

for /l %%c in (100, -10, 0) do (
SET "a=0"
SET "delim=-"
SET "repname=%a%%delim%%%c"
ECHO %repname%
REM "C:\Program Files\Aimsun\Aimsun Next 8.3\Aimsun Next.exe" -script consoleScript.py "..\networks\microSDKtestNetwork.ang" %repname% -dontlookformissing
)

Expect repname to be "0-100", "0-90"..."0-0". However, the result is:

D:\Codes\aimsun_sdks_imove\scripts>(
SET "a=0"
SET "delim=-"
SET "repname=20"
ECHO
REM "C:\Program Files\Aimsun\Aimsun Next 8.3\Aimsun Next.exe" -script consoleScript.py "..\networks\microSDKtestNetwork.ang"  -dontlookformissing
)
ECHO is on.
alroc
  • 27,574
  • 6
  • 51
  • 97
YAN JI
  • 11
  • 2
  • Sorry, I finally find the solution:https://stackoverflow.com/questions/13805187/how-to-set-a-variable-inside-a-loop-for-f – YAN JI Jan 08 '19 at 03:52
  • You will find the documentation in `set /?` and `setlocal /?`. You can use `call` to a `lable` to avoid these restrictions. However in your code you have no need for any of the above to concern you. You are needlessly assigning variables. Apart from the fact it is slow, the purpose of the `%%%n` variables are to be used which you are wasting. So `Set delim` and `set a` declared outside the loop. And just use `%a%%delim%%%c` in your final command. **Rule of programming 1** *Do not declare unnecessary variables*. – CatCat Jan 08 '19 at 04:19
  • And as `delim` and `a`b are really constants. They can be literally inserted, saving two slow variables. – CatCat Jan 08 '19 at 04:21
  • Sorry for the misleading - I will changing "a" value many times and also use "delim" variable many times to create a list of argv. Thanks. – YAN JI Jan 11 '19 at 03:14

1 Answers1

0
for /l %%c in (100, -10, 0) do Echo "C:\Program Files\Aimsun\Aimsun Next 8.3\Aimsun Next.exe" -script consoleScript.py "..\networks\microSDKtestNetwork.ang" 0-%%c -dontlookformissing

Is all you need.

M--
  • 25,431
  • 8
  • 61
  • 93
CatCat
  • 483
  • 4
  • 5