July, 2012    • The Old New Thing      Reading the output of a
command into a batch file variable       It's Day Two of Batch
File Week. Don't worry, it'll be over in a few days.      There
is no obvious way to read the output of a command into a batch
file variable. In unix-style shells, this is done via
backquoting.       The Windows command processor does not have
direct backquoting, but you can fake it by abusing the FOR
command. Here's the evolution:      The /F flag to the FOR
command says that it should open the file you pass in
parentheses and set the loop variable to the contents of each
line.      for /f %%i in (words.txt) do echo [%%i]      The loop
variable in the FOR command takes one percent sign if you are
executing it directly from the command prompt, but two percent
signs if you are executing it from a batch file. I'm going to
assume you're writing a batch file, so if you want to practice
from the command line, remember to collapse the double percent
signs to singles.      I'm cheating here b