Page 1 of 1 1
Topic Options
#171862 - 2006-12-21 07:20 AM Using System Variables in Kixtart
jimsullivan Offline
Lurker

Registered: 2006-12-21
Posts: 1
Loc: Tasmania, Australia
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

Top
#171863 - 2006-12-21 07:25 AM Re: Using System Variables in Kixtart [Re: jimsullivan]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.

Top
#171865 - 2006-12-21 07:29 AM Re: Using System Variables in Kixtart [Re: jimsullivan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
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

Top
#171868 - 2006-12-21 09:07 AM Re: Using System Variables in Kixtart [Re: jimsullivan]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
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?
_________________________



Top
#171875 - 2006-12-21 01:58 PM Re: Using System Variables in Kixtart [Re: Jochen]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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"

Top
Page 1 of 1 1


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

Who's Online
0 registered and 329 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.052 seconds in which 0.022 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