Page 1 of 1
how to get the return value on variable
Posted: 31 Oct 2007 04:51
by jebesh_s
Dear Gurus,
I am reading the regedit by
REG QUERY "HKLM\Software\Oracle" /v FORMS60
the return value is like below :
FORMS60 REG_EXPAND_RZ d:\forms6i\FORMS60
How may i store the return value on a variable
Please Help me
Thanks
Jebesh
Posted: 02 Nov 2007 10:03
by bsod
FOR "TOKENS=1-3,DELIMS= " %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C
Posted: 05 Nov 2007 01:21
by jebesh_s
Thanks for your response
how can i show the return value which is hold on the variable
Thanks
Jebesh
Posted: 05 Nov 2007 07:01
by bsod
ECHO %RESULT%
Posted: 05 Nov 2007 07:21
by jebesh_s
Thanks
could you please explain the use of token1-3 and delimeter=, in that line
Thanks
Antony
Posted: 05 Nov 2007 07:41
by jebesh_s
I have written the script like this below
FOR "TOKENS=1-3,DELIMS= " %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C
echo %result%
pause
it shows the following error message
"TOKENS=1-3,DELIMS=" Was unexpected at this time.
I am new to dos script please tel me is there any mistake in the above script
please help me to resolve it
Thanks
Jebesh
Posted: 06 Nov 2007 00:18
by jeb
Hi jebesh_s,
try it with FOR /F or first with FOR /?.
The "Token" part only works with the /F option.
caio
jeb
Posted: 06 Nov 2007 00:34
by jebesh_s
thanks for reply,
if i user for /f it accepts the token part, but it is not accepting the delimeters parts
my script is
--------------
FOR /f "TOKENS=1-3,DELIMS=" %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C
echo %result%
pause
it raise the following error
Delims=" was unexpected at this time
Thanks
Jebesh S
Posted: 06 Nov 2007 05:13
by jebesh_s
No Response?
Posted: 06 Nov 2007 05:37
by bsod
Well spotted Jeb
Thats what happens when you don't test.....
/F needs to be included, but its not there so that tokens and delims work. /F identifies that the 'set' in the round brackets is not a filename to be interrogated, but either a file with a list of filenames in it, or a command that the individual lines ouput, are treated as the results and parsed to the variable defined (%%A B and C in this case.)
The default for DELIMS is SPACE and TAB. so without TOKENS defined, the fist space in the output is deamed as a delimiter and therefore %%A results in FORMS60 %%B is not defined and neither is %%C and will equal nothing.
This line would work aswell.
FOR /F "TOKENS=1-3" %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C
ECHO %result%
Your delims doesn't work cos you have missed the SPACE after the equals sign.
,DELIMS= "
but as I said you dont need it, its just good practice.
ANYWAYS,
Now that i've looked a bit harder at it, it appears that the output does have TABS in it and also lots of lines that we are not interested in, so use this line to be exact.
FOR /F "TOKENS=1-3 SKIP=4" %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C
DID everyone follow that?
BSOD
Posted: 06 Nov 2007 06:26
by jeb
Hi,
Well spotted Jeb
Thats what happens when you don't test.....
ok, ok, you are right I don't test...
Now that i've looked a bit harder at it, it appears that the output does have TABS in it and also lots of lines that we are not interested in, so use this line to be exact.
FOR /F "TOKENS=1-3 SKIP=4" %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C
DID everyone follow that?
No.
Because it works sometimes, but not really exact.
If the result value has spaces in it (like a path to c:\Documents and Settings) you only get c:\Documents
Better use, Tokens 1-2* so you get also three tokens, but the last one contains the rest of the line
FOR /F "TOKENS=1-2* SKIP=4" %%A IN ('REG QUERY HKLM\Software\Oracle /v FORM') DO SET result=%%C
test and peace
jeb