I think I know what's happening now.
Correct me if I'm wrong.
You said that the script stops becos it got replaced by the other instance.
Is that becos the instances share the same script
(and thus the same name and name space)?
If this is the reason, would it help if
I have one script file for each instance?
(Since I know before hand how many instances I need)

PS - The other problem I have with using fork() is that
     I am developing on Win32, but the script will be used
     on Unix equivalent eventually.....


Alan Swan

-----Original Message-----
From: Philip Newton [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 27, 2000 4:22 PM
To: 'Alan Swan'; Perl-Win32-Users Mailing List
Subject: Re: Call exec repeatedly


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
BEGIN:VCARD
VERSION:2.1
N:Swan;Alan;;Mr
FN:Alan Swan
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20000424T060142Z
END:VCARD

Reply via email to