From: David Resnick on
I need to execute multiple simultaneous system() statements. I
originally did this using perl threads each invoking a system cmd,
waiting for them to be joinable, then harvesting the return status
with join(). The system commands are well behaved in that they will
finish eventually (have built in time limits). Unfortunately, I
discovered that the perl I need to use on some of our systems was
built without threads and replacing it isn't an option.

Is there a nice way to do this AND get the return values of the
processes launched in single threaded perl? Repeated system("$cmd &")
would execute all the processes, but I would need some way to get the
return status. Fork and exec would also work, but same issue. I
could run a wrapper that calls system and writes the result to a file
I guess, but that feels clunky. Any suggestions that seem nicer?

From: Dr.Ruud on
David Resnick wrote:

> I need to execute multiple simultaneous system() statements.

push @exit, system("$_ &") for @command;


> [...] Unfortunately, I
> discovered that the perl I need to use on some of our systems was
> built without threads and replacing it isn't an option.

Consider it a blessing. Just fork and wait.

--
Ruud
From: David Resnick on
On May 20, 10:00 am, "Dr.Ruud" <rvtol+use...(a)xs4all.nl> wrote:
> David Resnick wrote:
> > I need to execute multiple simultaneous system() statements.
>
> push @exit, system("$_ &") for @command;
>
> > [...]  Unfortunately, I
> > discovered that the perl I need to use on some of our systems was
> > built without threads and replacing it isn't an option.
>
> Consider it a blessing. Just fork and wait.
>
> --
> Ruud
Forking twice and waiting for both to exit (and checking $?, which was
the thing I forgot about) seems to work nicely. Thanks very much for
your help.
From: C.DeRykus on
On May 20, 11:14 am, David Resnick <lndresn...(a)gmail.com> wrote:
> On May 20, 10:00 am, "Dr.Ruud" <rvtol+use...(a)xs4all.nl> wrote:> David Resnick wrote:
> > > I need to execute multiple simultaneous system() statements.
>
> > push @exit, system("$_ &") for @command;
>
> > > [...]  Unfortunately, I
> > > discovered that the perl I need to use on some of our systems was
> > > built without threads and replacing it isn't an option.
>
> > Consider it a blessing. Just fork and wait.

>
> Forking twice and waiting for both to exit (and checking $?, which was
> the thing I forgot about) seems to work nicely.  Thanks very much for
> your help.

IPC::Run can process in the background, eg,
(Also options for IO, timeout, etc)

use IPC::Run qw/start/;

$ref1 = sub{ system "/path/to/foo1";
print "foo1: $?"; };
$ref2 = sub { system "/path/to/foo2";
print "foo2: $?"; };

my $h = start $ref1, '&', $ref2
or die "finish: $?";

--
Charles DeRykus
From: C.DeRykus on
On May 20, 2:34 pm, "C.DeRykus" <dery...(a)gmail.com> wrote:
> On May 20, 11:14 am, David Resnick <lndresn...(a)gmail.com> wrote:
>
> ...
> IPC::Run can process in the background, eg,
> (Also options for  IO, timeout, etc)
>
> use IPC::Run qw/start/;
>
> $ref1 = sub{ system "/path/to/foo1";
>               print "foo1: $?"; };
> $ref2 = sub { system "/path/to/foo2";
>               print "foo2: $?"; };
>
> my $h = start $ref1, '&', $ref2
>      or die "finish: $?";
>

last line should be replaced with
these below:

my $h = start $ref1, '&', $ref2;
finish $h or die "finish: $?";

--
Charles DeRykus