Assign Command Output To Variable In Batch File


Answer :

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.


This post has a method to achieve this

from (zvrba) You can do it by redirecting the output to a file first. For example:

echo zz > bla.txt set /p VV=<bla.txt echo %VV% 

You can't assign a process output directly into a var, you need to parse the output with a For /F loop:

@Echo OFF  FOR /F "Tokens=2,*" %%A IN (     'Reg Query "HKEY_CURRENT_USER\Software\Macromedia\FlashPlayer" /v "CurrentVersion"' ) DO (     REM Set "Version=%%B"     Echo Version: %%B )  Pause&Exit 

http://ss64.com/nt/for_f.html

PS: Change the reg key used if needed.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?