#142724 - 2005-06-30 04:52 PM
Calling a variable in a Kix script passed from a batch file
|
UJS
Fresh Scripter
Registered: 2005-06-30
Posts: 6
|
Greetings all,
I have a batch file for which I need to set a temp variable similar to how it is done in our login script. For lack of better explaining, I'll try to show what I need to do.
In our Login script, we pull the following information that is set as an enviromental variable
$CITY=SUBSTR(@USERID,3,2) $SEGMENT=SUBSTR(@USERID,5,1) $PHONE=SUBSTR(@USERID,6,5) $HOMEDRV=$CITY+$SEGMENT+$PHONE
From a batch file, I need to temporarly set %homedrv% the same way but with a variable that I'll pass from the batch file to the kix script. If I was passing it to another batch file, I'd use this syntax
call batch.bat %variable%
In batch.bat, my variable is %1
For my Kix script, I was assuming I would pass it similar to this
call kix32 script.scr %variable%
What would I replace @USERID with to use that variable?
$CITY=SUBSTR(@USERID,3,2) $SEGMENT=SUBSTR(@USERID,5,1) $PHONE=SUBSTR(@USERID,6,5) $HOMEDRV=$CITY+$SEGMENT+$PHONE
Thanks in advance for any suggestions.
Best Regards,
UJS
|
|
Top
|
|
|
|
#142726 - 2005-06-30 05:06 PM
Re: Calling a variable in a Kix script passed from a batch file
|
UJS
Fresh Scripter
Registered: 2005-06-30
Posts: 6
|
Quote:
This is written up in the KiX documentation for sure.
You would use something like this: Code:
kix32.exe myscript.kix $HOMEDRV=%homedrv%
Thanks for the reply. In your example, that would be how I would grab my homedrv variable that returns from the kix script correct? But how do I supply the kix script with the variable I want to process?
In our logon script, that variable is @userid, I need to change that to a variable that will be passed from the batch file.
Best Regards,
UJS
|
|
Top
|
|
|
|
#142728 - 2005-06-30 05:17 PM
Re: Calling a variable in a Kix script passed from a batch file
|
UJS
Fresh Scripter
Registered: 2005-06-30
Posts: 6
|
Quote:
Environment variables (%VARIABLE%) are directly accessible in KiXtart, you don't need to pass them in.
In the sample you were given, the KiXtart variable $HOMEDRV is being set to the value of %HOMEDRV% - this is another way of doing it, if somewhat redundant.
Be careful if you are using one of the test / beta releases, as passing variables on the command line was broken in one version.
Thanks for the reply.
I do realize that %homedrv% is already set as a enviromental variable and I should have been clearer. 
The batch that I'm running will not be running as the logged in user but as an administrator remotely. Basically, any enviromental variables that are set for the user won't be available as my script is running.
Best Regards,
UJS
|
|
Top
|
|
|
|
#142732 - 2005-06-30 09:11 PM
Re: Calling a variable in a Kix script passed from a batch file
|
UJS
Fresh Scripter
Registered: 2005-06-30
Posts: 6
|
Quote:
k, this is also said in manual but you just want to pass values to kix, right?
so, just call it like: (w)kix32.exe myscript.kix $variable="myvalue"
and that's it.
Good afternoon all,
Thanks again for the replies, I'm headed in the right direction.
Using the syntax posted above, I'm able to set the variable that I need with a variable that I provide. The script runs and HOMEDRV gets set. However, when that script exits and returns to my batch file or even a cmd prompt, the %homedrv% variable is set to whatever it was before the script runs. To get the proper %homedrv%, I must exit and open a new cmd window.
The two workarounds that I can think of would be,
1. write %homedrive% to a text file and grab my variable from there to continue with my batch file execution
or
2. Find a way to return $HOMEDRV as a return code which I can use to continue executing the script.
I have tried 1. but I'm afraid my understanding of Kix logic is in it's infant stages and I'm unable to get it to work.
Basically my attempt has been REDIRECTOUTPUT("c:\temp\HOMEDRV.txt",overwrite) ? $HOMEDRV
But the contents of HOMEDRV.txt are
0 PR10398
Can anyone explain why I'm getting the '0' on the first line or how I can get rid of this? The second line is the information that I need.
Best Regards,
UJS
|
|
Top
|
|
|
|
#142735 - 2005-06-30 09:43 PM
Re: Calling a variable in a Kix script passed from a batch file
|
UJS
Fresh Scripter
Registered: 2005-06-30
Posts: 6
|
I found the correct syntax for the REDIRECTOUTPUT in the FAQ
Thanks.
I currently have what I need to continue but it sure would be slick if I could just return $HOMEDRV to the cmd window 
Thank you all for your help.
Best Regards,
UJS
|
|
Top
|
|
|
|
#142738 - 2005-06-30 11:02 PM
Re: Calling a variable in a Kix script passed from a batch file
|
UJS
Fresh Scripter
Registered: 2005-06-30
Posts: 6
|
Quote:
Why not just lose the BATch file entirely and do it all in KiX?
For me that would be alot like jumping off the high dive without learning to swim :-)
I'm very comfortable with batch files and for most things, they work wonderfully. For now, it's when I encounter a shortcoming that is when I look elsewhere. As I become more comfortable with KIX, I'll do more. For only my 2nd kix script, I'm happy with what I've accomplished.
Thanks again for the rapid responses to my n00b questions.
Best Regards,
UJS
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1046 anonymous users online.
|
|
|