开发者

For /f and REG QUERY output and parentheses, trying to find JRE home

Im trying to write a batch file to find the JRE directory by querying the registry.

I'm using REG QUERY which is returning the following output:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Java RuntimeEnvironment\1.6
JavaHome    REG_SZ    C:\Program Files (x86)\Java\jre6

Im then trying to use FOR /F to return the JavaHome value as below:

FOR /F "usebackq skip=2 tokens=3*" %%B IN (`REG QUERY "%JAVA_VERSION%" /v %JAVA_HOME_NAME% 2^>nul`) DO (
echo %%B)

Problem is this returns only c:\Program Files. At first i thought that's fine I just need the next token as its split on the f开发者_如何学编程ollowing space but that doesnt work, so Im assuming it's the parentheses that's the problem.

Question is, how do I succesfully retrieve the java path from the reg query output?


Figured it out, I misunderstood usage of the tokens parameter. 3* will return consecutively named parameters for each token it finds so in this case i needed to access: %%B and %%C to get the full path.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜