• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to? tokens and delims problem

Nov 3, 2012
25
0
#1
Hi guys, this is my CMD batch:

FOR /F tokens^=5^ delims^=\^" %%G IN ('REG QUERY "HKCR\http\shell\open\command" /v ""') DO SET Default=%%G

It works perfectly, but once compiled with Take Command (.btm file), my scripts doesn't work anymore... Have you an idea to correct it? Thanks in advance.
 
#3
T
I never use that syntax myself, but isn't the whole TOKENS and DELIMS business supposed to go in double quotes?
That's correct, and documented. But with the documented syntax, you can't use a double-quote as a delimiter. So the OP used the kludge (find it on stackoverflow or superuser)
Code:
tokens^=5^ delims^=\^"
which is considered a single argument (as if it were quoted) because all the normal argument separators have been escaped.

I doubt Rex will feel compelled to emulate that behavior. In TCC, do it like this:
Code:
v:\> FOR /F "tokens=5 delims=\^q" %G IN ('REG QUERY "HKCR\http\shell\open\command" /v ""') DO echo %G
command
 -osint -url
... which is correct ... double the quotes on the variable G if you like.
 
#4
Here's a nice way to do it with TCC.
Code:
v:\> echo %@word["\^q",3,%@regquery[HKCR\http\shell\open\command\]]
 -osint -url
(which is correct).
Notice how brief and to-the-point it is ... and that running the external REG.EXE is not necessary.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,497
45
Albuquerque, NM
prospero.unm.edu
#7
What's the goal? To get the filename of the default web browser?

You can get the default open string with:
Code:
echo %@ftype[http]
To grab the first word of that string:
Code:
echo %@word[0,%@ftype[http]]
And to strip off the path and get just the filename:
Code:
echo %@filename[%@word[0,%@ftype[http]]]
 
#8
Yup! @FTYPE is a little easier than @REGQUERY.
Code:
v:\> echo %@ftype[http]
"l:\Firefox\firefox.exe" -osint -url ""
Once you have that string, you can extract from it whatever information you want. A few examples have been given.
 
Top Bottom