Page 1 of 1 1
Topic Options
#180564 - 2007-09-13 08:38 PM How do i get an error code from one Script to a Parent script
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
Hello every one,

I got this dilemma. I wrote a lot of small useful kixtart scripts but recently I needed a way to return an error code from one kixtart script to a parent kixtart script. we are talking scripts here, not a Function.

I do understand you can return a return value from a function to a script. But my case is a Parent Kix script calling another kixstart script using SHELL "WKIX32.EXE childscript.kix".

Is there a way for the childscript to return an error code and let the parent script deal with the error code ?

My Brain is low on caffeine and solutions. I need Help from the Kixtart Squad. It will be very greatfull.
_________________________
Treat people the way you want to be treated.

Top
#180567 - 2007-09-13 08:56 PM Re: How do i get an error code from one Script to a Parent script [Re: MarcInCa]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could define your variables as global variables.

 Quote:

GLOBAL
Action
Declare one or more global variables.

Syntax
GLOBAL "variable1" [<,>"variablex"]

Remarks
Global variables are visible everywhere in every script during the current KiXtart session.

Examples
GLOBAL $X
GLOBAL $X, $Y, $Z
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180569 - 2007-09-13 09:15 PM Re: How do i get an error code from one Script to a Parent script [Re: Mart]
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
Now that is one cool idea ! Correct me if i am wrong :

The Main "Script" Define:
GLOBAL $ERROR_RETURN_CODE

The children script would "set" the $ERROR_RETURN_CODE value before ending. Then the Parent script would use the value "setted by the child". \:\)
_________________________
Treat people the way you want to be treated.

Top
#180572 - 2007-09-13 09:18 PM Re: How do i get an error code from one Script to a Parent script [Re: MarcInCa]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yep.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180574 - 2007-09-13 09:21 PM Re: How do i get an error code from one Script to a Parent script [Re: Mart]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well it depends on how that child script is ran. If it's just a CALL then yes but if you spawn another KiX32 then no it won't work that way.
Top
#180575 - 2007-09-13 09:21 PM Re: How do i get an error code from one Script to a Parent script [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
I've never done this before, but since he's shelling out and starting a new kix32 environment, wouldn't this only work if you CALLed the script instead?

[edit: Doc beat me to the punch by about 30 seconds. /edit]
_________________________
(... better days ahead)

Top
#180578 - 2007-09-13 09:32 PM Re: How do i get an error code from one Script to a Parent script [Re: Allen]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
When you use Exit on the spawned script, pass a parm to it and that will be returned to the parent script. There is a FAQ 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
#180580 - 2007-09-13 09:36 PM Re: How do i get an error code from one Script to a Parent script [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Missed the part about calling and shelling. You guys are right. Using call the global vars will work with shell they won't. Les also has a good solution.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180583 - 2007-09-13 09:59 PM Re: How do i get an error code from one Script to a Parent script [Re: Les]
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
 Originally Posted By: Les
When you use Exit on the spawned script, pass a parm to it and that will be returned to the parent script. There is a FAQ on that.


Hoooo ! I see ! God I am learning a lot today.. (More coffee is brewing)

So if I call the child script with the SHELL command, the child script must have an EXIT command with the error code set. That way the parent Script will be able to use the value returned using @ERROR.

See example code below:

Parent Script:
....
SHELL "WKIX32 Childscript.kix"
IF (@ERROR = 0)
   Alll is well
ELSE
   We got an error
ENDIF

Childscript:
...
IF $Test_successful
   EXIT 0
ELSE
   EXIT 99
ENDIF

Is this correct ?


Edited by MarcInCa (2007-09-13 10:00 PM)
_________________________
Treat people the way you want to be treated.

Top
#180584 - 2007-09-13 10:12 PM Re: How do i get an error code from one Script to a Parent script [Re: MarcInCa]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
I think you would be better of calling the scripts using the Call command instead of shelling out to a new kix process each time a child script needs to start.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180586 - 2007-09-13 10:29 PM Re: How do i get an error code from one Script to a Parent script [Re: Mart]
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
Ho Dear ! You mean the SHELL call might not work and I should be using the call instead ?

OK guess i have to change some functionality for my main script but that wont be a big problem.

So the @ERROR value in the main script would not be set properly based on the SHELL call to another Kix script ?


Edited by MarcInCa (2007-09-13 10:37 PM)
_________________________
Treat people the way you want to be treated.

Top
#180588 - 2007-09-13 10:44 PM Re: How do i get an error code from one Script to a Parent script [Re: MarcInCa]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: MarcInCa

....
So the @ERROR value in the main script would not be set properly based on the SHELL call to another Kix script ?


That's not what I mean. If you call each child script it works for sure. Shelling out to a new kix session for each child script just seems useless to me because the console the main script is running in just sits around doing nothing and waiting for the child script to finish. If that's the want you want to do it or must do it its ok. To be sure that the vars go from the child script to the main script that way you should do some tests.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#180591 - 2007-09-13 11:04 PM Re: How do i get an error code from one Script to a Parent script [Re: Mart]
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
Haaa Thank you for clearing this up ! (Still Learning the power of Kix here) \:\)

Good news ! Based on every one's feed back, I did a bit of test scripting.

The EXIT command works well as we "exit" the ChildScript, when we use the CALL or SHELL command from the Parent Script.

The Parent script does get the return code from the Child Script in the @ERROR variable.

Mission accomplished. Good work every one. Thank you all ! \:\)

Time to write some Kix Ass Code. ;\)
_________________________
Treat people the way you want to be treated.

Top
#180592 - 2007-09-13 11:19 PM Re: How do i get an error code from one Script to a Parent script [Re: MarcInCa]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There are pros and cons to both methods. If you SHELL to another instance of KiX and it bombs, your parent script is still alive. If you CALL a child script and it bombs, you are blown out of the water.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#180593 - 2007-09-13 11:42 PM Re: How do i get an error code from one Script to a Parent script [Re: Les]
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
Hoo Geee ! Good point ! Humm Noted and will look into that. ;\)
_________________________
Treat people the way you want to be treated.

Top
#180618 - 2007-09-14 03:47 PM Re: How do i get an error code from one Script to a Parent script [Re: MarcInCa]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Best of both worlds:
Parent - Global $CHILD_EXIT ; define the global

Child:
$CHILD_EXIT = ; set the exit status if we are CALLED
Exit $CHILD_EXIT ; exit with it if we are SHELLED

Now, if you CALL the child, the global var CHILD_EXIT is set, and if you "SHELL KIX32 child.kix", the @ERROR is set, so a
 Code:
CALL 'Child.kix'
'Result is ' $CHILD_EXIT ?

will be the same as
 Code:
SHELL 'KIX32 child.kix'
$CHILD_EXIT = @ERROR

so you can then evaluate $CHILD_EXIT either way.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#180619 - 2007-09-14 04:08 PM Re: How do i get an error code from one Script to a Parent script [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
One more thing... If you use the $CHILD_EXIT method, your child scripts should start with a
If Not Declared($CHILD_EXIT)
Global $CHILD_EXIT
EndIf

if you use SetOption(Explicit, on) in your child script AND expect to continue to use the child scripts independent of the parent.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#180688 - 2007-09-18 07:16 PM Re: How do i get an error code from one Script to a Parent script [Re: Glenn Barnas]
MarcInCa Offline
Fresh Scripter

Registered: 2007-06-05
Posts: 22
Loc: Montreal, Canada
Thank you Glen ! Gee indeed the $CHILD_EXIT method is the best of both worlds !

Your insight is very appreciated ! \:D
_________________________
Treat people the way you want to be treated.

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

Generated in 0.088 seconds in which 0.042 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