Page 1 of 1 1
Topic Options
#176786 - 2007-06-06 10:30 AM "CALL" without waiting
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
I hope one of you guys can give me some inspiration… :-)

I want to “CALL” a KiX script from a KiX script – but I don’t want the first script to wait for the second KiX script to complete before continuing.

I realise I could call the second script by using the “RUN” statement. Using this method would require that I specify the kix32.exe interpreter and the name of my second script – which isn’t too much of a problem.

However, it would be nice if I could ‘call’ the second script without executing a second interpreter.

It would be nice if the “CALL” statement had an optional argument…

CALL “script name” [, WaitState]

Where an optional WaitState represents…

0 = Wait until called script finishes before continuing with the first script. This would be the default and current behaviour.
1 = Continue first script without waiting for called script to complete.

Does anyone have any ideas on how I can do what I want? In addition, what do you think of the “CALL” statement with the optional argument.

Thanks in advance,

Lee

Top
#176787 - 2007-06-06 10:43 AM Re: "CALL" without waiting [Re: Lee Wilmott]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
I don’t think there is an easy way to get this done without starting a new kix session.

Just a small comment about the waitste option.
If it makes it into the kix executables it should be an optional parameter.
It should default to the current behavior when the parameter is not supplied because it would break a lot of scripts if it was mandatory imho.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#176791 - 2007-06-06 10:53 AM Re: "CALL" without waiting [Re: Mart]
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
I didn't think there was a way. :-(

 Originally Posted By: Mart
Just a small comment about the waitste option.
If it makes it into the kix executables it should be an optional parameter.
It should default to the current behavior when the parameter is not supplied because it would break a lot of scripts if it was mandatory imho.


I couldn't agree with you more - no question about it. In fact, it was because of that reason why I suggested an "optional" argument and suggested the default ought be the current behaviour! ;-)

If others like the idea then I'll post this suggestion in the "Suggestions" forum (and reference this post).

Any takers?

Thanks for your comments Mart!

Lee

Top
#176794 - 2007-06-06 11:34 AM Re: "CALL" without waiting [Re: Lee Wilmott]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
The current behaviour is logical, instead of calling another kix file, think of it calling a function, the script would also wait until the function is complete. This kinda behaviour was introduced in Windows 2000. Before that even batch scripts didn't wait for a command to finish.

Therefor I don't know if a Wait State could be implemented.

Top
#176796 - 2007-06-06 01:40 PM Re: "CALL" without waiting [Re: Arend_]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
A better suggestion would be to implement "fork()". This is when a process creates a second (child) copy of itself.

This allows you to have two independant processes, both of whos' variables are identical at the time of the fork. The only difference between the two is the value returned by the fork() function.

Fork() is the classic (and simplest) way of creating asynchronous threads.

In your scenario, the child thread would then perform the CALL, wheras the parent will continue to process the main script.

If your script and variable types are simple enough you can do what you want by calling Kix32.exe again with the script that you want to "CALL" and passing all your variables on the command line. It's a bit trickier if you need to pass arrays or objects.

Top
#176797 - 2007-06-06 01:48 PM Re: "CALL" without waiting [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
 Quote:
Before that even batch scripts didn't wait for a command to finish.

I gotta disagree here. BAT files have been synchronous until NT/Win32, when the "Start" command was introduced. This allowed you to spawn the command as a child process and allow continued execution of the script. "Start" takes a WAIT arg to allow the script to wait while the command runs in a separate child environment. Of course, there have always been apps you call from a bat file that spawn a child that continues - Oracle Client installer is one of those insidious processes!

As for Call NoWait, it would be useful to me, since I currently have a multi-threaded Kix app that processes hundreds of small tasks, and maintains about 25 running at any one time. This is used to generate daily system reports, and running them serially by one process can take several hours. Running them multi-threaded, the task is done in under 15 minutes (with 100% CPU load for much of that time). Using Call NoWait would allow me to embed the external script as a function and save quite a bit of system resources.

It's important to realize that any process you do not wait for must be independent - it will not return status or values! (Just like Run - it doesn't return values, and the status it returns is based on how the command started, not ended.) It must handle its own data (although should be able to receive values) and deal with its own errors.

The huge advantage of a Call Nowait would be that the Kix environment would be inherited (hopefully as a copy), which is not what happens with Run/Shell.

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

Top
#176798 - 2007-06-06 03:09 PM Re: "CALL" without waiting [Re: Glenn Barnas]
Lee Wilmott Offline
Starting to like KiXtart

Registered: 2002-09-17
Posts: 106
Loc: Bristol, UK
Thanks for your comments guys. Do I have enough support here to allow me to create a post in the "Suggestions" forum? :-)

Lee

Top
#176799 - 2007-06-06 03:49 PM Re: "CALL" without waiting [Re: Lee Wilmott]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It's actually been suggested a couple of times.

You could add your "what he said" to one of the extant threads, such as this one:

http://www.kixtart.org/forums/ubbthreads...true#Post166650

Top
#176803 - 2007-06-07 11:09 AM Re: "CALL" without waiting [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Well Glenn, for schools that used some elementary software which required a cd I used to make iso's out of them and their shortcuts pointed to batch files wich would mount the iso in daemon tools and then call the required executable.

The batch files on the 9x OS's wouln't wait until the iso is loaded.
The same batch files did work waiting until each command is finished before proceeding to the next command on 2K/XP/2K3.

Top
#176804 - 2007-06-07 12:55 PM Re: "CALL" without waiting [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
What you're seeing there is the behavior similar to the Oracle client installer, in which the command you call to initiate the installation in turn forks another process. The child runs to complete the install, while the parent dies, returning control to the batch file. It's poor installer design in my opinion, usually the result of a developer that's never automated the install. It's an issue with the exe being called, and not BAT scripting in general.

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

Top
#176805 - 2007-06-07 03:24 PM Re: "CALL" without waiting [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
 Originally Posted By: Glenn Barnas
It's an issue with the exe being called, and not BAT scripting in general.


Like I said, the same bat file, same exe file on 2K/XP/2K3 works with waiting until the command is finished. And not on 9X OS's.

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 138 anonymous users online.
Newest Members
MaikSimon, kvn317, kixtarts2025, SERoyalty, mytar
17872 Registered Users

Generated in 0.135 seconds in which 0.011 seconds were spent on a total of 14 queries. Zlib compression enabled.

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