in reply to Re: Capturing errors from 3-arg pipe open in ActivePerl 5.020
in thread [SOLVED] Capturing errors from 3-arg pipe open in ActivePerl 5.020

Sorry, I feel a bit dense here, but what do I do with the PID once I have it? I get a PID regardless of whether or not the command succeeded.

pipe.pl

#!/usr/bin/perl use 5.018; use strict; use warnings; my $pid = open (my $ARTICLE, "-|", "caesar") or die "Can't start caesa +r: $!\n$^E"; my $read = <$ARTICLE>; say "[$read][$pid]";
Results:
perl pipe.pl 'caesar' is not recognized as an internal or external command, operable program or batch file. Use of uninitialized value $read in concatenation (.) or string at pip +e.pl line 9. [][1236]

Replies are listed 'Best First'.
Re^3: Capturing errors from 3-arg pipe open in ActivePerl 5.020
by Lotus1 (Vicar) on Nov 16, 2015 at 18:53 UTC

    You asked in the OP what is different about your command and why isn't the 'or die' clause working in your open command. I provided documentation that shows if you open a pipe it returns the pid instead of just non-zero or zero like with opening a file. That is the difference and the answer to your question.

    I wasn't telling you to do anything with the pid, only that it is the return value and the reason why your code didn't work as expected.

    I don't think this example should be included in the documentation for open since it doesn't work as expected for pipes.