in reply to Returning status to parent from pipe

Be the shell and do the piping yourself.

use IPC::Open3 qw( open3 ); local *TO_CHLD; local *PIPE; local *FR_CHLD; my $com1_pid = open3(*TO_CHLD, *PIPE, '>STDERR', 'com1'); my $com2_pid = open3('<PIPE', '*FR_CHLD', '>STDERR', 'com2'); ... waitpid($com1_pid, 0); # $? is com1_pid's status waitpid($com2_pid, 0); # $? is com2_pid's status

Replies are listed 'Best First'.
Re^2: Returning status to parent from pipe
by morrin (Acolyte) on Aug 25, 2010 at 21:22 UTC
    Thanks for the suggestion. However I am trying to figure out how easily I could integrate that into my code. I left out some of the details, but basically I am forking a series of commands which I first predefine. Some have single commands and some are combinations of commands. I can always do a "hack" by breaking up the commands e.g
    job[0] = "com1 | com 2" job[1] = "com3" . . . job[n] = "com100"
    can become
    job[0] = "com1 > tmp.out" job[1] = "cat tmp.out >com2" job[3] = "com3" . . . job[n+1] = "com100"
    Ideally I was trying to find a solution like Crackers2's suggestion where I can do some "magic" on each command to get it to return the first exit code. I will play around with that for a while and see if I can do that