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

Did you also change your code to look like the following:
my $error = join('', <$PROG_STDERR>); my $err = $!; die "Error reading data from STDERR: $err" if !eof($PROG_STDERR);

If you didn't, you haven't shown than an error even occurred.

Before I do anything else, I'm going to worry about making sure an error actually occurred and about getting the right error message when one does occur.

Replies are listed 'Best First'.
Re^4: open3 and illegal seeks
by brainsick (Sexton) on Jul 07, 2009 at 19:09 UTC
    The other changes you suggested do prevent the error from happening. If the illegal seek error isn't coming from the read then where is it coming from? What's setting $!?

    I do see how the "or die" on the join could be a logic error on my part because it's going to be the value of the assignment that's checked, which if there's nothing in STDERR, would be empty, which would trigger the "or" condition.

    Something still doesn't add up in my mind though.

      The other changes you suggested do prevent the error from happening.

      No, it means an error never occurred in the first place.

      What's setting $!?

      Some earlier call or some internal call. You could use command line utility strace if you think it's relevant.

      I do see how the "or die" on the join could be a logic error

      Two problems:

      • Your use of $! in the error message when it's not warranted.

      • It does a bad job of detecting an error when one occurs. An error could occur and you wouldn't even know it. (False negative)

      If you *also* want to make sure you received more than zero characters, that's fine. Add that check.

        I was including $! in the error text because my Programming Perl, 3rd Edition book has the $! icon next to the readline function which is the implementation of the <FILEHANDLE> operator. If that's incorrect, then I'll omit it from the error message.

        Does this pass muster:
        my $error = ''; if (!eof($PROG_STDERR)) { $error = join('', <$PROG_STDERR>) or die "Error reading data from +STDERR"; } close($PROG_STDERR); print "error: $error\n";
        You've given me some insight into the problem I've been fighting with. Thank you.