You neglected to say what problem you are having with IO::Tee?
You might like to try this barebones implementation. save the following into a directory\file called
x:\perl\site\lib\My\Tee.pm
My::Tee
package My::Tee; use Tie::Handle; our @ISA = qw[ Tie::Handle ]; sub TIEHANDLE { die "Usage: tie *STDxxx, 'My::Tee', 'logfilepath'" unless @_ == 2; open my $std, '>', 'CON' or die "Couldn't reopen STDxxx : $!" and return; my( $flush, $old ) = ( $|, select( $std ) ); $| = $flush; select( $old ); open my $log, '>', $_[1] or die "Couldn't open $_[1] for output: $!" and return; bless { log => $log, stdout => $std }, $_[0]; } sub PRINT { my $self = shift; print { $self->{ log } } @_; print { $self->{ stdout } } @_; } sub PRINTF { my $self = shift; printf { $self->{ log } } @_; printf { $self->{ stdout } } @_; } 1;
The add this line to the top of your program where xxx is either OUT or ERR. Add two lines if you want to redirect both, but you will have to use separate log files for them in this case!.
tie *STDxxx, 'My::Tee', '\path\to\logfile';
You should then find that any print or printf statements end up in the log file. If you want to use syswrite etc. you'll need to add to the module. See perltie for more information if you want to attempt this.
In reply to Re: Writing to Screen and file on Win32
by BrowserUk
in thread Writing to Screen and file on Win32
by banesong
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |