in reply to How to know the status of a command invoked by open function?

What makes you think execution was successful? Like Perl is telling you, it wasn't successful. You closed its STDOUT before it was done writing to it.

Update: I figured out why 141. It's (1<<7)|SIGPIPE. This is the shell letting the parent know how its kid exited.

# No shell involved, and the child died from SIGPIPE: $ perl -e'open(PS,"ls . |") or die "$!"; close PS or die $!; printf("% +04X\n", $?);' 000D # The shell relaying how its child died via its exit code: $ perl -e'open(PS,"ls . 2>/dev/null |") or die "$!"; close PS or die $ +!; printf("%04X\n", $?);' 8D00

Replies are listed 'Best First'.
Re^2: How to know the status of a command invoked by open function?
by zhujian0805 (Sexton) on Aug 16, 2011 at 00:55 UTC
    Thanks.
    
    But how can i get the exit status for the command in this case?
    open(PS,"ls . 2>/dev/null |")
    
    why the following two opens have different result?
    open(PS,"ls .|")
    open(PS,"ls . 2>/dev/null |")
    
    Thanks
    James

      [ Please don't use <pre>...</pre>. Use <p> at the start of paragraphs and use <c>...</c> around computer text (code, data, output, etc). ]

      why the following two opens have different result?

      open(PS,"ls . 2>/dev/null |")
      is equivalent to
      open(PS, '-|', /bin/sh', '-c', 'ls . 2>/dev/null ')
      but
      open(PS,"ls . |")
      get optimised to
      open(PS, '-|', 'ls', '.')

      Also see the update to my original reply.

      But how can i get the exit status for the command in this case?

      You already know how. It's in $? after a successful close. In this case, it's 141. The shell returns 141 (128|SIGPIPE) when its child dies from SIGPIPE.

        it's weird that i get return code '0' when i run my script on AIX.