Page 1 of 1 1
Topic Options
#142724 - 2005-06-30 04:52 PM Calling a variable in a Kix script passed from a batch file
UJS Offline
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
#142725 - 2005-06-30 04:57 PM Re: Calling a variable in a Kix script passed from a batch file
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
This is written up in the KiX documentation for sure.

You would use something like this:
Code:

kix32.exe myscript.kix $HOMEDRV=%homedrv%



Edited by oobnuker (2005-06-30 04:57 PM)
_________________________
-- oobnuker - .KIX hack - no really.

Top
#142726 - 2005-06-30 05:06 PM Re: Calling a variable in a Kix script passed from a batch file
UJS Offline
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
#142727 - 2005-06-30 05:13 PM Re: Calling a variable in a Kix script passed from a batch file
Richard H. Administrator Offline
Administrator
*****

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

Top
#142728 - 2005-06-30 05:17 PM Re: Calling a variable in a Kix script passed from a batch file
UJS Offline
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
#142729 - 2005-06-30 05:48 PM Re: Calling a variable in a Kix script passed from a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#142730 - 2005-06-30 06:03 PM Re: Calling a variable in a Kix script passed from a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
When KiX starts, it gets a copy of the environment. Any venviro vars set by another process will not be seen by KiX. Enviro vars are not a good way to pass info between processes.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142731 - 2005-06-30 06:25 PM Re: Calling a variable in a Kix script passed from a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, I think that is already understood.
as far as I see, this is the same thing I've seen replied in this thread for quite many times.
and I don't believe that is not part of the issue either.
_________________________
!

download KiXnet

Top
#142732 - 2005-06-30 09:11 PM Re: Calling a variable in a Kix script passed from a batch file
UJS Offline
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
#142733 - 2005-06-30 09:32 PM Re: Calling a variable in a Kix script passed from a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
THe 0 is the return code from RedirectOutput. There are several FAQs on that.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142734 - 2005-06-30 09:37 PM Re: Calling a variable in a Kix script passed from a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Have you tried SETL in your script?

[edit] nevermind


Edited by Les (2005-06-30 09:39 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142735 - 2005-06-30 09:43 PM Re: Calling a variable in a Kix script passed from a batch file
UJS Offline
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
#142736 - 2005-06-30 09:45 PM Re: Calling a variable in a Kix script passed from a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Also you put the CRLF (?) before the $HOMEDRV so you would still have a blank line in your text file. There is a FAQ on that too.

$RC = RedirectOutput('c:\temp\HOMEDRV.txt',1) $HOMEDRV ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142737 - 2005-06-30 09:47 PM Re: Calling a variable in a Kix script passed from a batch file
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why not just lose the BATch file entirely and do it all in KiX?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#142738 - 2005-06-30 11:02 PM Re: Calling a variable in a Kix script passed from a batch file
UJS Offline
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
#142739 - 2005-07-01 12:15 AM Re: Calling a variable in a Kix script passed from a batch file
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
UJS, dude, where the heck you need env vars?!?
if your scripts can run without them, where you need them?
what you mean the env var is set back?
I can't see anywhere you changing it in the first place...

and why you still look at them?
skip those thingies, we live in NT based era, leave dos stuff in the past, k?
_________________________
!

download KiXnet

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 1046 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.069 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org