jimsullivan
(Lurker)
2006-12-21 07:20 AM
Using System Variables in Kixtart

I have a script where I have to run a batch file to obtain a variable because it is not obtainable in kixtart. Inside the batch file I assign it a variable:
set abc = directory path.

I can check with to confirm that the variable was correctly applied:
echo %abc%

When I try to use the variable in kixtart:
$a = %abc%
? "The value of the variable is " $b

It appears to have no value

Has anyone experienced this problem, and solved it

Cheers
Jim


NTDOCAdministrator
(KiX Master)
2006-12-21 07:25 AM
Re: Using System Variables in Kixtart

Hi Jim and welcome to the board.

Please let us know what version of KiXtart you're using and also post your KiXtart code (using CODE TAGS) and your batch file so we can see what can be done to get it to work for you.

Thanks.


AllenAdministrator
(KiX Supporter)
2006-12-21 07:29 AM
Re: Using System Variables in Kixtart

What are you running that you cannot get into Kix... you might try searching for WSHPipe...

I can't test your variable... but this works as expected.
Code:
$a = %temp%
? "The value of the variable is " + $a


JochenAdministrator
(KiX Supporter)
2006-12-21 09:07 AM
Re: Using System Variables in Kixtart

Originally Posted By: jimsullivan

$a = %abc%
? "The value of the variable is " $b


The use of $b in your code is just a typo, no?


Richard H.Administrator
(KiX Supporter)
2006-12-21 01:58 PM
Re: Using System Variables in Kixtart

If you are running the BAT file from within KiXtart then the environment variable is only created in the child process. Any child process that it creates will see the new environment variable, but it won't be visible to the parent (the KiXtart script).

The best solution is to convert the BAT file to KiXtart, then you won't have a problem.

If you cannot convert the BATch file to KiXtart there are a couple of ways of passing variables back to the parent. Simple integers (if they are small enough) can be passed by using them as the exit value, and checking @ERROR. The drawback of this is that you cannot differentiate between data and a real error.

Another method is to pass the values back via an intermediary, such as a file - this works for complex numbers and strings, and also allows you to return more than one variable.

This example has a BATch file SETVAR.BAT which sets two variables. The BATch file is called from the KiXtart GETVAR.KIX script, and passes the variable data back via a temporary INI file.

GETVAR.KIX
Code:
; Temporary file used to pass variables
$sTempFile=%TEMP%+"\Var"+@TICKS+".ini"
; Create INI file template
$=RedirectOutput($sTempFile,1) "[BATVARS]"+@CRLF $=RedirectOutput("")
; Call BAT file
Shell '"'+%COMSPEC%+'" /C setvar.bat "'+$sTempFile+'"'
; Read variables
$ABC=ReadProfileString($sTempFile,"BATVARS","ABC")
$DEF=ReadProfileString($sTempFile,"BATVARS","DEF")
; And display...
"ABC="+$ABC+@CRLF
"DEF="+$DEF+@CRLF
; Clean up
DEL $sTempFile


SETVAR.BAT
Code:
@SET ABC=Foo
@SET DEF=Bar
@ECHO ABC="%ABC%" >> "%1"
@ECHO DEF="%DEF%" >> "%1"