in reply to Re: Undestanding this code snippet
in thread Undestanding this code snippet

Thanks everyone for replying, you are right, there is a "|" as the file handle is opened...apologize that I missed that when I modified the command before posting :( (open F, "some_shell_expression |";)

With that said, is there still a way for catching that system error with the current code?
Thanks again!

Replies are listed 'Best First'.
Re^3: Undestanding this code snippet
by shmem (Chancellor) on Jul 21, 2008 at 20:17 UTC

    Yes - see IPC::Open3. That module provides capturing STDERR of a command. The exit status is available after reaping the child with waitpid. Example (untested):

    my $pid = open3('<&STDIN', \*CHLD_OUT, \*CHLD_ERR, "some_shell_express +ion"); while(<CHLD_OUT>) { # do something with that command's output } my $err = <CHLD_ERR>; # may block - better use select here waitpid $pid, 0; if ( $? ) { warn $_[0] . ($? == -1) ? "failed to execute: $!\n" : ($? & 127) ? sprintf "child died with signal %d, %s coredump\n", ($? & 127), ($? & 128) ? 'with' : 'without' : sprintf "child exited with value %d\n", $? >> 8; }

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}