#126428 - 2004-09-09 11:48 PM
Importing Environmental Variables
|
xpanmanx
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
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.
|
|
Top
|
|
|
|
#126433 - 2004-09-10 09:04 PM
Re: Importing Environmental Variables
|
xpanmanx
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
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
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
|
|
|
|
#126437 - 2004-09-10 10:12 PM
Re: Importing Environmental Variables
|
xpanmanx
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
|
|
|
|
#126439 - 2004-09-10 10:31 PM
Re: Importing Environmental Variables
|
xpanmanx
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
|
|
|
|
#126443 - 2004-09-10 10:46 PM
Re: Importing Environmental Variables
|
xpanmanx
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
|
|
|
|
#126446 - 2004-09-10 10:54 PM
Re: Importing Environmental Variables
|
xpanmanx
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
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 811 anonymous users online.
|
|
|