how to get the return value on variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jebesh_s
Posts: 8
Joined: 31 Oct 2007 04:36
Location: Chennai

how to get the return value on variable

#1 Post by jebesh_s » 31 Oct 2007 04:51

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

bsod
Posts: 6
Joined: 19 Oct 2007 05:21

#2 Post by bsod » 02 Nov 2007 10:03

FOR "TOKENS=1-3,DELIMS= " %%A IN ('REG QUERY HKLM\Software\Oracle /v FORMS60') DO SET result=%%C

jebesh_s
Posts: 8
Joined: 31 Oct 2007 04:36
Location: Chennai

#3 Post by jebesh_s » 05 Nov 2007 01:21

Thanks for your response
how can i show the return value which is hold on the variable

Thanks
Jebesh

bsod
Posts: 6
Joined: 19 Oct 2007 05:21

#4 Post by bsod » 05 Nov 2007 07:01

ECHO %RESULT%

jebesh_s
Posts: 8
Joined: 31 Oct 2007 04:36
Location: Chennai

#5 Post by jebesh_s » 05 Nov 2007 07:21

Thanks

could you please explain the use of token1-3 and delimeter=, in that line

Thanks
Antony

jebesh_s
Posts: 8
Joined: 31 Oct 2007 04:36
Location: Chennai

#6 Post by jebesh_s » 05 Nov 2007 07:41

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

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#7 Post by jeb » 06 Nov 2007 00:18

Hi jebesh_s,

try it with FOR /F or first with FOR /?.
The "Token" part only works with the /F option.

caio
jeb

jebesh_s
Posts: 8
Joined: 31 Oct 2007 04:36
Location: Chennai

#8 Post by jebesh_s » 06 Nov 2007 00:34

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

jebesh_s
Posts: 8
Joined: 31 Oct 2007 04:36
Location: Chennai

#9 Post by jebesh_s » 06 Nov 2007 05:13

No Response?

bsod
Posts: 6
Joined: 19 Oct 2007 05:21

#10 Post by bsod » 06 Nov 2007 05:37

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

jeb
Expert
Posts: 1041
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#11 Post by jeb » 06 Nov 2007 06:26

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. :wink:
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

Post Reply