Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to set %_INIREAD result to variable

@INIREAD returns the item's value, unless there is an error -- the file doesn't exist, the section doesn't exist, etc. -- in which case it's supposed to return -1.

@INIWRITE, by contrast, is supposed to return 0 or -1; not the value you've written. If you don't want the 0 or -1 in those variables, then don't use those variables. (I often use a variable RV for "return value", which I can check later if I want to.)

Finally, SET should have one equals sign, with no spaces. (It seems to work as written, but it's always safer to use the documented syntax.)
 
Code:
~\Work> type test.ini
[xyzzy]
foo=123
bar=455

~\Work> set x=%@iniread[".\test.ini",xyzzy,foo]

~\Work> set x
123

~\Work> unset y

~\Work> set y == %@iniread[".\test.ini",xyzzy,foo]

~\Work> set y
y == 123

~\Work> echo %y%
ECHO is OFF

~\Work> echo %[y ]
= 123

~\Work>

SET X == anything
does not set envvar X at all. It sets a variable whose name is X followed by a space.

The first = terminated the name of the envvar (ending in a space) and the second = became the first character of the value.
 
Finally, SET should have one equals sign, with no spaces. (It seems to work as written, but it's always safer to use the documented syntax.)

That may look like it works.
Code:
v:\> set zzz == foo

v:\> set zzz
zzz == foo

But I'm confident it isn't doing what's intended. Above, the variable name is "zzz " and it's value is "= foo".
Code:
v:\> echo %[zzz ]
= foo
 

Similar threads

Replies
4
Views
2K
Back
Top