问题
Consider the following result from a hypothetical reg query
:
..>reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MediaPlayer /v "I
nstallation Directory"
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MediaPlayer
Installation Directory REG_EXPAND_SZ %ProgramFiles%\Windows Media Play
er
How do I grep the output so that I can assign the actual value of the setting (%ProgramFiles%\...
) into a variable (or temp file)?
回答1:
example for batch files:
@FOR /F "tokens=2* " %%A IN ('reg query HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MediaPlayer /v "Installation Directory"') DO @SET PARAM=%%B
If you want to use it directly in console - use single percent sign to denote variables (i.e. %A
and %B
)
来源:https://stackoverflow.com/questions/4073486/grepping-reg-query-result-value