in reply to Reading only STDERR

parent.pl:
#!perl -l use IPC::Open3; $pid = open3(\*WTRFH, \*RDRFH, \*ERRFH, 'perl child.pl'); while (<ERRFH>) { print "Received error message <$_>"; }
child.pl:
#!perl for (1..5) { print STDERR "Message $_\n"; }
output of perl parent.pl:
Received error message <Message 1 > Received error message <Message 2 > Received error message <Message 3 > Received error message <Message 4 > Received error message <Message 5 >

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Reading only STDERR
by nomis80 (Sexton) on Apr 06, 2005 at 13:52 UTC
    Sure, but then the STDOUT of child.pl gets lost. Try adding a line in child.pl:
    #!perl for (1..5) { print STDERR "Message $_\n"; print STDOUT "STDOUT $_\n"; }
    You'll see that what's printed to STDOUT doesn't get displayed, because it ends up in parent.pl's RDRFH. I want the STDOUT of child.pl to correspond to parent.pl's STDOUT, not to be a pipe.
      I hadn't discerned from your original post what you wanted done with STDOUT. To have it sent to parent's STDOUT, you do this in parent.pl:
      $pid = open3(\*WTRFH, '>&STDOUT', \*ERRFH, 'perl child.pl');

      Caution: Contents may have been coded under pressure.
        Thank you very much, that's exactly what I needed. I hadn't realized that you were supposed to write the name of the filehandle in a string. I thought it didn't make much sense, but hey, does Perl make any sense at all? Thanks again!
      I want to open a process and read only its STDERR

      So, do you want STDOUT or not? Your first questions states very clearly that you want to read only STDERR. It's very hard to read someones mind to know they do not ask want they want to know.... :-(
      Pleas learn to ask questions in a proper way

      Paul