Here is the goal.  I want to launch another application from which I can get
the status, stdin, and stdout after the application closes.  Will the
following code work for the general case of applications that do not need
additional input and will not hang?

--

#!/usr/bin/perl -w

use strict;
use Carp;
use IPC::Open3;
use Data::Dumper; 

my @children;

{
    local (*TO_CHILD, *FROM_CHILD, *ERROR_CHILD);
    my $child = open3(*TO_CHILD, *FROM_CHILD, *ERROR_CHILD,
            "/usr/bin/cal", "2004");
    push @children, [$child, *TO_CHILD, *FROM_CHILD, *ERROR_CHILD];
}
{
    local (*TO_CHILD, *FROM_CHILD, *ERROR_CHILD);
    my $child = open3(*TO_CHILD, *FROM_CHILD, *ERROR_CHILD,
            "/usr/bin/cal", "boo");
    push @children, [$child, *TO_CHILD, *FROM_CHILD, *ERROR_CHILD];
}

print Dumper([EMAIL PROTECTED]);

foreach my $child (@children)
{
    waitpid ($child->[0], 0);
    my $result = ($? >> 8) & 0xff;
    
    print "$child->[0] exited with status $result\n";
    print "output:\n" . join "", readline($child->[2]);
    print "error:\n" . join "", readline($child->[3]);
    
    close $child->[1];
    close $child->[2];
    close $child->[3];
}

-- 
Thane
Thane at crashbox dot com

Reply via email to