0

How can I expand a variable in a variable in batch file? This should print compiler64.exe instead it prints PLATFORM%

setlocal EnableDelayedExpansion
set PLATFORM=X64
set FLAGS_COMPILER_X86=compiler32.exe
set FLAGS_COMPILER_X64=compiler64.exe
set FLAGS=%FLAGS_COMPILER_%PLATFORM%%
echo %FLAGS%
Mofi
  • 46,139
  • 17
  • 80
  • 143
user6033608
  • 93
  • 1
  • 1
  • 7
  • See [here](http://stackoverflow.com/questions/35532216/cmd-piping-echo-to-set-expanding-variables-in-variables/35538235#35538235) or [here](http://stackoverflow.com/questions/35639223/find-all-ocurences-of-letter-change-to-diffrent-letter/35642840#35642840)... – Aacini Mar 14 '16 at 16:55
  • This is not the same thing! – user6033608 Mar 14 '16 at 17:46
  • You want this instead: `set FLAGS=!FLAGS_COMPILER_%PLATFORM%!` – Bill_Stewart Mar 14 '16 at 19:55
  • I changed the description that appear at the given link, changed _3 words_ (and the examples) and got this: "If you want to use _another variable_ in a variable name, then you must know that the replacement of variables enclosed in percents by their values is parsed _from left to right_; this mean that: `%FLAGS_COMPILER_%PLATFORM%%` don't give the desired result because it mean: show the value of `%FLAGS_COMPILER_%` variable, followed by `PLATFORM`, etc... – Aacini Mar 14 '16 at 20:41
  • To solve this problem you must use _Delayed Expansion_, that is, insert `setlocal EnableDelayedExpansion` command at beginning, enclose other variable in percents, and enclose the original variable in exclamation marks: `!FLAGS_COMPILER_%PLATFORM%!`" You should learn to read a general description in a way that it adapts to your particular problem. – Aacini Mar 14 '16 at 20:42

0 Answers0