Alan Swan wrote:
> I have a script I want to run 6 instances of it simultaneously.
> So I have a calling script to loop 6 times using exec to run it.
> But my calling script always dies after the first loop.

Did you read the documentation for exec (`perldoc -f exec`)? It says:

     The `exec()' function executes a system command *AND
     NEVER RETURNS* - use `system()' instead of `exec()' if
     you want it to return.

So, when you call exec() the first time, the first perl process is replaced
by the second perl process, and there is no trace left. The documentation
also says:

     Since it's a common mistake to use `exec()' instead of
     `system()', Perl warns you if there is a following
     statement which isn't `die()', `warn()', or `exit()' (if
     `-w' is set - but you always do that).

So if you ran your script with -w, it should have warned you about this.

> Anyone has any suggestions why it stops running the other instances?

Because it's replaced by the second script.

> And why the calling script doesn't print out its test statements?

Probably because the string was written to the stdio buffer, but it didn't
get flushed to the output before the exec. If you had set $| to 1 at the
beginning, you should have seen it.

> And any suggestions how to call these instances simultaneously
> (other than using fork? becos I'm not too sure how to use it...  :|)

I think you have to use fork() (or threads). I thought of replacing "exec
..." with "system ...", but `perldoc -f system` says that it:

     Does exactly the same thing as "`exec LIST'", except
     that a fork is done first, and the parent process waits
     for the child process to complete.

So, since system() waits for search2.pl to complete, you'd be running it six
times consecutively and not simultaneously.

Alternatively, on Win32 (since this *is* Perl-*Win32*-Users), I think
there's something like Win32::StartProcess or so, that might help you. Don't
know any details though, or even its proper name.

Cheers,
Philip

---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to