I realized that I need to be more specific about my requirements.

My perl script calls arbitrary perl subs or scripts which do arbitrary
things. I hope good things. I'm not always sure. I am usually in control
of the subs but sometimes other people are.

I would like to replace the STDERR and STDOUT filehandles in perl s.t. I
can capture what is going on as well as give normal feedback to the user
running the script at the Terminal.

Later, when I'm done with my calls into the arbitrary perl subs, I can
examine my local copy of stderr and stdout and report (either by log or
email or whatever). 

Thus, I need a function that sort of looks like:

sub LogArbitrarySub
        {
        my $aSub = shift @_;

        {
        local *STDOUT = <something>;
        local *STDERR = <something>;
        exec '$aSub(@_)';
        }

        # now theoretically I have files or something with the contents
and relative times of stdout/err
        # report them
        }

So, tying a filehandle doesn't seem like it would work, although I must
admit to be largely ignorant of ties and how they work or why you'd want
to use them (outside of OOP).

Calling IPC::Open3 won't work, because there's not a good way of writing
a sub to a file for another invocation of Perl to run (AFAIK). Correct
me if I'm wrong.

What I'm thinking is that I'm going to have to open pipes and fork a
child to sit there and watch the pipes and spew information to STDOUT or
STDERR and also back to the parent along with time information. Andrew
Langmead suggested using IO::Pty to avoid the stdio buffering problems,
which I think I might need to do, but I'm unsure whether I'd need one
pseudo-tty or two.

Thanks,
nh

-----Original Message-----
From: Nathan Herring [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, February 12, 2003 8:44 PM
To: [EMAIL PROTECTED]

I want to be able to write a perl script that does advanced logging of
both itself and the system() calls it makes.

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.

e.g. if I had something like

$| = 1;

print STDERR "Why don't you";
print STDOUT " eat my";
print STDERR " shorts?\n";

I might end up with something like

[ { type => 'STDERR', time => 1, text => "Why don't you" },
  { type => 'STDOUT', time => 1.0001, text => " eat my" },
  { type => 'STDERR', time => 1.0002, text => " shorts?\n" }]

in memory somewhere...

Is there something out there that already does this? Or does it on
arbitrary numbers of filehandles/io::handles?

Thanks in advance,
nh



Reply via email to