Jlmartinez
(Getting the hang of it)
2012-10-23 10:20 AM
Variable from bat to kix

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!!


Mart
(KiX Supporter)
2012-10-23 10:54 AM
Re: Variable from bat to kix

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


Jlmartinez
(Getting the hang of it)
2012-10-23 11:59 AM
Re: Variable from bat to kix

Thanks Mart!! Itīs OK!!
Another thing that iīve learned!!!!


Glenn BarnasAdministrator
(KiX Supporter)
2012-10-23 02:55 PM
Re: Variable from bat to kix

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


Jlmartinez
(Getting the hang of it)
2012-10-24 12:30 PM
Re: Variable from bat to kix

Thanks Glenn!! All this, is clear now!!