On Wed, Feb 12, 2003 at 08:43:51PM -0800, Nathan Herring wrote:
> One of my desired goals is to replace STDERR and STDOUT in such a way
> that
> 1) the command line user still sees them both, and as they are output
> (not strangely buffered)
> 2) I have a log of every snippit of STDERR and STDOUT with the time (in
> granularity more fine than seconds, if possible) it arrived and in the
> order that it was received.

I would suggest to take a the IPC::Open3 module that comes with perl.
You pass it three filehandles, one for the program's standard input,
one for its standard output, and one for standard error.

To be able to read both filehandles simultaneously in order to report
their contents to the user, you might want to use the IO::Select to
determine when one of them has data ready.

This may or may not handle all of your requirements. The one last
aspect is the buffering. Using IPC::Open3 and select won't add any
additional buffering, but since the output of the external program is
no longer a terminal and is now a pipe, it will possibly acquire
stdio's standard buffering semantics and start block buffering
standard output. (I guess the idea that the designers of stdio had was
that programs run interactively needed immediate feedback. When output
was piped it could switch to a more efficient mode.) If you have
control of the external program, you might want to force it's standard
output to be unbuffered. If you don't, you might need to use something
like the CPAN module IO::Pty.



-- 
"Maybe I should be in Hollywood!"  -- Samantha Langmead, age 5. 
on learning how to use iMovie.

Reply via email to