Re: Problem with Perl system()
am 18.12.2007 19:48:16 von smallpondOn Dec 18, 8:13 am, Julie
> I'm using Windows XP Pro and running Perl 5.8.8 under Cygwin.
>
> I have a Perl program that calls another Perl program using system().
>
> The driver program repeatedly calls the main Perl program.
>
> for ( my $i = 0 ; $i < $retries ; $i++
> {
> for ( my $j = 0 ; $j < $num_devices ; $j++ )
> {
> system( "perl main.pl parm1 parm2 &" ) ;
> }
> sleep 60 ; # never gets here
>
> }
>
> I put the call to system() within a loop and (almost) everything is fine.
>
> The only problem is that after the last call to system(), the outer loop
> doesn't gain control. The process seems to be hung.
> I've put warn statements everywhere in the driver program but that
> hasn't yielded any clues.
>
> I know that main.pl is terminating because there's only one Perl process
> running after the last call to system().
>
> It doesn't matter whether I run one or a hundred calls to system().
>
> **** Here's what's very interesting: If I run main.pl under the Perl
> debugger then press 'c' to continue (no breakpoints etc.), then the
> program behaves perfectly; control is passed to the outer loop after the
> last system() call.
>
> I'm using strict, warning, diagnostics pragmas. I've also tried main.pl
> without the pragmas.
>
> What can I do to resolve this problem?
system emulates fork which !-e on Windows, so there are many
issues with it.
To start a bunch of cooperating perl tasks, maybe take a
look at Win32::ProcFarm.
--S