Page 1 of 3 123>
Topic Options
#126428 - 2004-09-09 11:48 PM Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Code:
If Open(1,'c:\temp\envars.bat') = 0

$envvar = SubStr(Lcase(ReadLine(1)),5)
While @ERROR = 0
???????????????????????
$envvar = SubStr(Lcase(ReadLine(1)),5)
Loop
Close(1)
EndIf

Greetings,

The ??????????????????????? in my code represents the function that I need, but don't know and can't find. Maybe it's SET or SETL or SETM, but those don't seem to produce the results that I'm looking for.

I'm trying to read a textfile and convert each line into a variable useable by the current script. The textfile is line after line of 'set=' commands.

I need a function that will ultimately take this string: var1=abc123, and set var1 as a variable readable by the current script, just as if the statement var1=abc123 existed verbatim.

I can't call a batch before the script. The final product must be a single, packaged, executeable Kix Script.

Can you help me ?

Best regards,

Tim ==

Top
#126429 - 2004-09-10 12:21 AM Re: Importing Environmental Variables
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
a couple questions.

Where does this file come from - is it generated by you?

Why are you using a BAT file to set environment vars?

Is there any reason you can not use some other format of file to hold your variable values?

Why are you trying to parse the BAT file in stead of just referencing the environment variable directly?

Check out the "Execute" command.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#126430 - 2004-09-10 12:27 AM Re: Importing Environmental Variables
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Read the manual. You cannot affect the current environment. Why would you even have to use the %var% when you could use $var?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#126431 - 2004-09-10 08:39 AM Re: Importing Environmental Variables
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les has a point.
if you want to (like you said) play with the vars in the current kix script, you should go with internal variables.
_________________________
!

download KiXnet

Top
#126432 - 2004-09-10 03:29 PM Re: Importing Environmental Variables
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
How do you need to use these variables. here's a little snippet that will store each line of the text file (after the '=') into an array.

Code:

dim $varArray
$ = open(1,"yourfile")
$curLine = readline(1)
while @error = 0
redim preserve $varArray[ubound($varArray)+1]
$val = split($curLine,'=')[1]
$varArray[ubound($varArray)] = $val
$curLine = readline(1)
loop
$ = close(1)

for each $var in $varArray
? $var
next

_________________________
Eric

Top
#126433 - 2004-09-10 09:04 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Quote:

Where does this file come from - is it generated by you?



It is generated by a very long and involved set of DOS batch and VBS scripts.

Quote:

Why are you using a BAT file to set environment vars?



Those other scripts write into that file by redirecting echo statements, or by redirecting STDOUT of other scripts, or of compiled programs.

Quote:

Is there any reason you can not use some other format of file to hold your variable values?



It is not within my authority to change the file format. Unfortunately.

Quote:


Why are you trying to parse the BAT file in stead of just referencing the environment variable directly?



From my OP: I can't call a batch before the script. The final product must be a single, packaged, executeable Kix Script.

Top
#126434 - 2004-09-10 09:07 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Quote:

Read the manual.



Now, Les, how do you think I managed to get this far?

Quote:

Why would you even have to use the %var% when you could use $var?



See my reply to Howard.

Top
#126435 - 2004-09-10 09:15 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Quote:

How do you need to use these variables. here's a little snippet that will store each line of the text file (after the '=') into an array.Code:

dim $varArray
$ = open(1,"yourfile")
$curLine = readline(1)
while @error = 0
redim preserve $varArray[ubound($varArray)+1]
$val = split($curLine,'=')[1]
$varArray[ubound($varArray)] = $val
$curLine = readline(1)
loop
$ = close(1)

for each $var in $varArray
? $var
next





Thanks, MacieP, you've jump-started my brain.

I need to get the variable names, in addition to the values. The names are static; the values are dynamic. I suppose I can do this by splitting the READLINE to the left and the right of the '='. I'm going to go experiment with that right now. Then there's the problem that one of the values is an LDAP address, which contains several '=' signs.

Top
#126436 - 2004-09-10 10:04 PM Re: Importing Environmental Variables
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Do you mean something like this?

Code:

$ = open(1,"c:\blah.txt")
$curLine = readline(1)
while @error = 0
$firstEqualPos = instr($curLine, '=')
$varName = substr($curLine,1,$firstEqualPos-1)
$val = '"' + substr($curLine,$firstEqualPos+1) + '"'
$ = execute("$$" + $varName + "=" + $val)
$curLine = readline(1)
loop
$ = close(1)

_________________________
Eric

Top
#126437 - 2004-09-10 10:12 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Code:
Break On

If Open(1,'c:\temp\envars.bat') = 0

$raw_line = Trim(SubStr(Lcase(ReadLine(1)),5))

While @ERROR = 0

$var_name = ''
$var_value = ''


;provide special handling for LDAP path
If InStr($raw_line,'CompPath')
For Each $element in Split($raw_line,'CompPath' + Chr(61))
$var_name = 'CompPath'
$var_value = $element
Next
GoTo SET_ENVVAR
EndIf

For Each $element in Split($raw_line,Chr(61))
Select
Case $var_name = '' $var_name = $element
Case $var_value = '' $var_value = $element
EndSelect
Next

:SET_ENVVAR
? $var_name + Chr(61) + $var_value
$var_name = $var_value

$raw_line = Trim(SubStr(Lcase(ReadLine(1)),5))

Loop

Close(1)

EndIf

? '___________________________________________________________________'

@CRLF

? '$$sitecode='$sitecode
? '$$oldcompname='$oldcompname

Get $

Return


That's my revised code. But lines 30 & 31 don't display the value.

The problem is surely in line 40. Would one of you gurus please help me with the syntax?

Thanks,

Tim ==

Top
#126438 - 2004-09-10 10:24 PM Re: Importing Environmental Variables
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
is there 40 lines in that code?
_________________________
!

download KiXnet

Top
#126439 - 2004-09-10 10:31 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Whoops, it's line 40 in the KSE display

It's line 23 in the UBB. It reads: $var_name = $var_value

(The line 30 & 31 references are correct.)

From maciep's suggestions, I'm testing a variant of that now, to no avail...Code:
Execute('$$' + $var_name '=' $var_value)

...I just keep getting beeped out of the script with a "missing comma" message.

I thought it might be an unmatched quote, but the KSE makes that kind of botched entry kind of difficult.

Still baffled,

Tim ==


Edited by xpanmanx (2004-09-10 10:34 PM)

Top
#126440 - 2004-09-10 10:33 PM Re: Importing Environmental Variables
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
you're missing some '+'s in your execute statement.

Execute('$$' + $var_name + '=' + $var_value)
_________________________
Eric

Top
#126441 - 2004-09-10 10:36 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Thanks, maciep - I copied your snippet verbatim - now I'm getting Error in Expression beeps...??
Top
#126442 - 2004-09-10 10:44 PM Re: Importing Environmental Variables
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
can you post the rest of the script again with those changes?
_________________________
Eric

Top
#126443 - 2004-09-10 10:46 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Code:
Break On

If Open(1,'c:\temp\envars.bat') = 0

$raw_line = Trim(SubStr(Lcase(ReadLine(1)),5))

While @ERROR = 0

$var_name = ''
$var_value = ''

;provide special handling for LDAP path
If InStr($raw_line,'CompPath')
For Each $element in Split($raw_line,'CompPath' + Chr(61))
$var_name = 'CompPath'
$var_value = $element
Next
GoTo SET_VAR
EndIf

For Each $element in Split($raw_line,Chr(61))
Select
Case $var_name = '' $var_name = $element
Case $var_value = '' $var_value = $element
EndSelect
Next

:SET_VAR
? '$$' + $var_name + '=' + $var_value
Execute('$$' + $var_name + '=' + $var_value)

$raw_line = Trim(SubStr(Lcase(ReadLine(1)),5))

Loop

Close(1)

EndIf

? '___________________________________________________________________'

@CRLF

? '$$sitecode=' + $sitecode
? '$$oldcompname=' + $oldcompname

Get $

Return


Top
#126444 - 2004-09-10 10:52 PM Re: Importing Environmental Variables
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
this is wrong if not having the var always have only numbers:
Execute('$$' + $var_name + '=' + $var_value)

more like:
Execute('$$' + $var_name + '="' + $var_value + '"')

would do...
anyway, I can't still believe this is really needed...
_________________________
!

download KiXnet

Top
#126445 - 2004-09-10 10:54 PM Re: Importing Environmental Variables
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
i'm confused on what you're trying to do here. Can you show a portion of the file you are reading too?
_________________________
Eric

Top
#126446 - 2004-09-10 10:54 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Starting not to feel so bad.

This is from the Kixtart 2001 v4.22 manual:

Code:
$Rc = Execute( ‘$$X = ’ + @USERID )


And it's causing the exact same error, when it is the only line in a brand new script!

Top
#126447 - 2004-09-10 10:57 PM Re: Importing Environmental Variables
xpanmanx Offline
Starting to like KiXtart

Registered: 2002-07-08
Posts: 108
Loc: St. Louis MO USA
Quote:

i'm confused on what you're trying to do here. Can you show a portion of the file you are reading too?



Code:
set AutoDeploy_Process_Type=Attended Network-based Migration
SET TIMEZONE=003
SET DAYS_TO_RETAIN_FULL_WORKSTATION_BACKUP=30
Set DISTRIBUTION_MEDIUM=Network
SET SERIALNUM=7GCXZ01
SET MACHINETYPE=COMPUTERS-XP
set CompPath=CN=7GCXZ01,OU=Outlook Mail Client,OU=Employees,OU=CORP,DC=CORP1,DC=CORP,DC=COM


Top
Page 1 of 3 123>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.553 seconds in which 0.087 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org