Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I was using IPC::Open2 as a replacement for a pipe'd open and got caught under windows because it seems to open in binmode.

Two questions:

  1. Did I miss something in the docs about IPC::Open2 opening in binmode?
  2. Can someone help explain what in IPC::Open3 is resulting in binmode.
test.pl
#!perl -w print <<EOF; Line one line two line three EOF
test script
use IO::Handle; use IPC::Open2; open FH, "perl test.pl|" or die $!; while (<FH>) { chomp; print "test1:[$_]\n"; } close FH; my ( $rdrfh, $wtrfh ); my $pid = IPC::Open2::open2($rdrfh, $wtrfh, 'perl','test.pl' ); while (<$rdrfh>) { chomp; print "test2:[$_]\n"; } open FH, "perl test.pl|" or die $!; my $fd = IO::Handle->new_from_fd( fileno(FH), "r" ); while ( <$fd> ) { chomp; print "test3:[$_]\n"; }
Results in:
C:\WINDOWS\Desktop>perl t.pl test1:[Line one] test1:[line two] test1:[line three] ]est2:[Line one ]est2:[line two ]est2:[line three test3:[Line one] test3:[line two] test3:[line three]
I know I can solve this with:

binmode $rdrfh, ':crlf';
But is reading in binary mode expected behavior?

Another question is why I cannot specify "rb" as the MODE above.

Thanks,

Replies are listed 'Best First'.
Re: Binmode and IPC::Open2
by liz (Monsignor) on Jul 29, 2003 at 23:06 UTC
    Knowing which version of Perl you're using, might help in this case. I recall seeming some issues on p5p in this regard for 5.8.0 on Windows. If you're nut running 5.8.0, then that's not the case.

    Liz

      Yes, sorry, Perl 5.6.1 on Win98.