develooper Front page | perl.perl5.porters | Postings from March 2000

bugs in 1) double-pipe open and 2) readline

Thread Previous
From:
Tom Christiansen
Date:
March 5, 2000 16:51
Subject:
bugs in 1) double-pipe open and 2) readline
Message ID:
13532.952303861@chthon
First, notice:

    % perl -we 'print scalar <STDOUT>'
    Filehandle main::STDOUT opened only for output at -e line 1.

Strange.  Readline forgot to return undef.  

Now, watch this:

    % perl -we 'open(OUT, "|cat"); print scalar <OUT>;close OUT'

Hold on.   There's no output, which is expected.  But there are
neither warnings for reading from a writeonly handle.  And readline
still doesn't report the failed read.

What started me down this was an even worse problem:

    open(BOTH_CAT, "|cat -un|") or die "no both cat: $!";
    select ((select(BOTH_CAT), $| = 1)[0]);
    print BOTH_CAT "stuff\n";
    print "Want stuff: ";
    print scalar <BOTH_CAT>;
    print BOTH_CAT "more stuff\n";
    print "Want more stuff: ";
    print scalar <BOTH_CAT>;
    close BOTH_CAT;
    print "Done.\n";

When run, you get:

    % perl -w ~/dubpipe
    Can't open bidirectional pipe at /home/tchrist/dubpipe line 1.
	 1  stuff
	 2  more stuff
    Want stuff: Want more stuff: Done.

Um, hello?  It complains and then goes and does it anyway, but only
half-way?  Why is this even *bothering* to fork and exec!?  And
then once it does, it only gives me half yet doesn't mutter a peep
when I make use of the other half.  You'd think that if it were
going to trouble itself to fork and exec, it would do the Right
Thing, but if--as I was expecting--it weren't going to do the Right
Thing, then it wouldn't bother to fork and exec in the first place.

This is not the classic behavior.

--tom

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About