Assign command output to variable in batch file

user2283234 picture user2283234 · Apr 25, 2013 · Viewed 109.6k times · Source

I'm trying to assign the output of a command to a variable - as in, I'm trying to set the current flash version to a variable. I know this is wrong, but this is what I've tried:

set var=reg query hklm\SOFTWARE\Macromedia\FlashPlayer\CurrentVersion>

or

reg query hklm\SOFTWARE\Macromedia\FlashPlayer\CurrentVersion >> set var

Yeah, as you can see I'm a bit lost. Any and all help is appreciated!

Answer

BDM picture BDM · Apr 25, 2013

A method has already been devised, however this way you don't need a temp file.

for /f "delims=" %%i in ('command') do set output=%%i

However, I'm sure this has its own exceptions and limitations.