seek(STDOUT, -0, 2) or die $!; print STDOUT "abc\n"; #### $ cat a.pl use Devel::Peek; open(SAVOUT, '>&STDOUT') or die $!; close(STDOUT) if $ARGV[0]; open(STDOUT, '+>', "/tmp/stdout.log") or die $!; Dump(*STDOUT{IO}); @argv = qw(/bin/echo hello world); system(@argv); print SAVOUT "before=", tell(STDOUT), "\n"; seek(STDOUT, 0, 0) or die $!; print SAVOUT "after=", tell(STDOUT), "\n"; while (1) { my $rv = read STDOUT, $_, 8192; die $! if !defined($rv); last unless $_; print SAVOUT "stdout=", $_; } print SAVOUT "at end=", tell(STDOUT), "\n"; close STDOUT; $ diff -u <(strace perl a.pl 0 2>&1) <(strace perl a.pl 1 2>&1) | less ... lseek(1, 0, SEEK_SET) = 0 lseek(1, 0, SEEK_CUR) = 0 -[ code to read locale-dependent version of error message] -write(2, "Bad file descriptor at a.pl line"..., 37Bad file descriptor at a.pl line 17. -) = 37 +read(1, "hello world\n", 4096) = 12 +read(1, "", 4096) = 0 +close(1) = 0 -write(3, "before=0\nafter=0\n", 17before=0 +write(3, "before=0\nafter=0\nstdout=hello wo"..., 46before=0 after=0 -) = 17 +stdout=hello world +at end=12 +) = 46 close(3) = 0 -exit_group(9) = ? -Process 4028 detached +exit_group(0) = ? +Process 4032 detached