in reply to open3 and illegal seeks

The following is wrong:
my $error = join('', <$PROG_STDERR>) or die "Error reading data from STDERR: $!";

Nothing in there indicates $! is meaningful. You're seeing the value left in $! by tell. At some level, tell($fh) is implemented as seek($fh,0,SEEK_CUR), but you can't use seek a pipe.

The best you can do follows:

my $error = join('', <$PROG_STDERR>); my $err = $!; die "Error reading data from STDERR: $err" if !eof($PROG_STDERR);

Replies are listed 'Best First'.
Re^2: open3 and illegal seeks
by brainsick (Sexton) on Jul 07, 2009 at 18:13 UTC
    ikegami,

    I only had the tell statements in there because I was trying to debug the illegal seek message and that was one of the straws that I grasped.

    Removing the tell statements and re-running the program still results in the illegal seek error:
    Error reading data from STDERR: Illegal seek at test_servicing_request +.pl line 74.
    Or did I miss the crux of your message?

    Also, how does that explain why my simple sample works but my real CGI script does not? Wouldn't the tell introduce the error in both instances?
      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.

        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.