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:
- Did I miss something in the docs about IPC::Open2 opening in binmode?
- 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,
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.