http://www.perlmonks.org?node_id=802517

samwyse has asked for the wisdom of the Perl Monks concerning the following question:

The following is putting the right stuff ('hello world\n') into the file, and the calls to tell() return what I'd expect. But my loop isn't printing anything, and the read() doesn't seem to be advancing the file pointer. Is there something I'm missing?
@argv = qw(/bin/echo hello world); open(SAVOUT, '>&STDOUT') or die $!; open(STDOUT, '+>', "/tmp/stdout.log") or die $!; system(@argv); print SAVOUT "before=", tell(STDOUT), "\n"; seek(STDOUT, 0, 0) or die $!; print SAVOUT "after=", tell(STDOUT), "\n"; while (1) { read STDOUT, $_, 8192; last unless $_; print SAVOUT "stdout=", $_; } print SAVOUT "at end=", tell(STDOUT), "\n"; close STDOUT;
And here's the output:
before=12 after=0 at end=0