I am not sure that you can read from STDERR while it is being written to, and of course if (say) it was being directed to a pipe or to /dev/null you couldn’t read it anyhow.
So, what if we try this ... In a shell script or somesuch, invoke your Perl program, taking care to put STDERR specifically to somewhere you can capture it. Capture STDOUT, separately, in the same way. When the Perl program ends, the shell script now cats (or types) those two streams into its own (the shell script’s...) STDOUT and/or STDERR as appropriate. The shell script is now simply a “wrapper,” and the job is done.
It could be very simple ... like this sketch of an idea:
perl ... your_program_name ... 1>/tmp/stdout 2>/tmp/stderr
cat /tmp/stdout
cat /tmp/stderr
rm /tmp/stdout /tmp/stderr
No, “the job wasn’t done in the way” that you might now be considering, but ... “the job is done.” It’s clean, and obvious, and very easily changed. Win32 and Unix/Linux implementations of the same idea are equally trivial.
|