How to set %_INIREAD result to variable

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,689
106
Albuquerque, NM
prospero.unm.edu
@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.)
 
May 29, 2008
572
4
Groton, CT
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.
 
May 20, 2008
12,178
133
Syracuse, NY, USA
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