in reply to Re^7: open3 and illegal seeks
in thread open3 and illegal seeks

Since I'm now only reading from $PROG_STDERR when there's data to be read (!eof), reading nothing does indicate an error, right?

It then stands to reason that the error will be stored in $! since the failure happened during the readline, right?

If I read between the lines, I think you're saying that by not checking eof after the read, I don't know whether I read all of the data. What conditions would cause me to be able to read some data and then fail midway through? Is that a likely scenario?

Replies are listed 'Best First'.
Re^9: open3 and illegal seeks
by ikegami (Patriarch) on Jul 08, 2009 at 17:34 UTC

    Since I'm now only reading from $PROG_STDERR when there's data to be read (!eof), reading nothing does indicate an error, right?

    It it was a file... But we're talking about a pipe. It might not be closed when you check eof, but it could close after you started trying to read from it.

    Or so I thought.

    eof apparently does a read to find out if more data is coming.

    $ perl -wle' open(my $fh, "-|", sleep => 5) or die $!; print eof($fh)?1:0; print defined(scalar(<$fh>))?1:0; print eof($fh)?1:0 ' <<eof blocks for 5 seconds here>> 1 0 1

    This behaviour is very different than the behaviour of stdio's feof, but it's documented: eof "Returns 1 if the next read on FILEHANDLE will return end of file, or if FILEHANDLE is not open."

    So, you're right. Reading nothing in that situation would indicate a reading error (and thus, you can print out $!).

    (No consideration was given to non-blocking handles.)

      If the data read from $PROG_STDERR consisted of "0" and nothing else, or any other string that evaluates to false in Perl then an error might be reported when there wasn't one.