Page 1 of 1 1
Topic Options
#206055 - 2012-10-23 10:20 AM Variable from bat to kix
Jlmartinez Offline
Getting the hang of it

Registered: 2008-05-20
Posts: 75
Loc: Sevilla, Spain
Hello everyone!! Thanks for your help and for this fantastic forum, i have learned a lot!!
And now, my question...

Is possible to pass a variable from bat to kix??

thanks for all!!

Top
#206056 - 2012-10-23 10:54 AM Re: Variable from bat to kix [Re: Jlmartinez]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4615
Loc: The Netherlands
You can set is as an environment variable for example. Kix can access environment variables and use them further on in the script.

Example BAT command:
 Code:
Set Test=123abc


Example kix code:
 Code:
Break on

$test = ExpandEnvironmentVars(%test%)

If $test = "123abc"
	;do something
Else
	;do something else
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#206057 - 2012-10-23 11:59 AM Re: Variable from bat to kix [Re: Mart]
Jlmartinez Offline
Getting the hang of it

Registered: 2008-05-20
Posts: 75
Loc: Sevilla, Spain
Thanks Mart!! Itīs OK!!
Another thing that iīve learned!!!!

Top
#206058 - 2012-10-23 02:55 PM Re: Variable from bat to kix [Re: Jlmartinez]
Glenn Barnas Moderator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4224
Loc: New Jersey
Consider the following:
With SET VAR=Value in a bat file that later calls Kix, that value will be available to the Kix script and any programs (including bat files) that are invoked by Kix RUN or SHELL commands, as well as commands in the original batch file that first invoked Kix32 but come after the Kix command. This is what Mart demonstrated above.

You can also pass values directly to variables in the Kix script:
 Code:
Set Var=123
Kix32.exe myscript.kix $KixVar1=%VAR% KixVar2="some text"
In this example, %VAR% is defined in the environment and passed directly to Kix as $KixVar1. A second value is passed directly to Kix as $KixVar2. This value is NOT available in the environment, and thus not visisble outside of the kixtart script. Just an alternative to the method above. You can also pass values to Kix on the command line that you can parse via the GetCommandLine() function. Changing the Kix line above to
 Code:
Kix32 myscript.kix %VAR% "some text"
will return that string directly or broken into an array of arguments. See the manual for complete syntax of GetCommandLine().

Finally, be aware that if you set an environment variable in a batch file that was invoked from a Kix RUN or SHELL command, that the value will NOT be returned to Kix. When you define an environment variable, any program called from that point forward will have a COPY of that value placed in its environment. This is a Parent/Child concept - the child program inherits a copy of its parent's environment. It can do anything to the variables without impacting the parent's values. If you need to run a command (batch file, exe, etc) and want to return a value to the (parent) Kix script, you should use something like the WSHPipe() UDF. This returns all of the output from the command directly to a Kixtart variable.

Glenn
_________________________

Actually I am a Rocket Scientist! \:D

Top
#206059 - 2012-10-24 12:30 PM Re: Variable from bat to kix [Re: Glenn Barnas]
Jlmartinez Offline
Getting the hang of it

Registered: 2008-05-20
Posts: 75
Loc: Sevilla, Spain
Thanks Glenn!! All this, is clear now!!


Edited by Jlmartinez (2012-10-24 12:30 PM)

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Chris S., Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
4 registered (Jochen, AndreLuiz, Flavien, Arend_) and 206 anonymous users online.
Newest Members
Sjaak, Biybucket, Markus1961, Ian231, kixnewbie12
17480 Registered Users

Generated in 0.057 seconds in which 0.025 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