开发者

Trying to store the out of a command to a variable and trying to match in batch file

I am trying to set variable to a registry path. And then querying a registry and trying to match with the variable.If both are same 开发者_运维问答then goto execute. But for some reason Im getting error and looks like there is some problem with this command

set var=HKEY_LOCAL_MACHINE\System\x

IF reg query==var
GOTO EXecute 


What you're doing there is just comparing strings. How should the command interpreter know that reg query is a command (besides the fact, that it alone won't yield much useful stuff anyway).

What you need to do here is execute your program, capture its output and then compare. You can do this with the for /f command:

for /f %%x in ('reg query ...') do ...

However, the output of reg is human-readable, not machine-readable, so you need some work to get it right. Basically you need to ignore empty lines in that for statement and the header line as well ... and then you need to find the actual value that's of interest to you. This will get ugly pretty fast.


for /f %%a in ('reg query ...') do if "%var%" == "%%a" goto Execute
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜