I'm looking for a way to tee STDERR so that all output to it also goes to a file. I'm using ActivePerl v5.20.2 for Windows. I tried code suggested in the topic https://www.perlmonks.org/?node_id=843501. It does tee STDERR, but not to the file I want. It creates a file named "GLOB(0xf7b278)" and the output goes to that file. It also creates the file I specified, but it's empty
use strict;
use warnings;
use open qw(:std :utf8); # Set the default encoding for STDIN, STDOUT
+& STDERR to UTF-8
use IO::Tee ();
my $logname = 'test-tee$.log';
open(my $logfile, ">:encoding(UTF-8)", $logname) or die qq(Can't open
+"$logname for writing"\n);
# Tee STDERR to log file. If running as Administrator, console window
+may disappear quickly!
open STDERR2, ">&=STDERR" or die "Failed to alias STDERR: $!";
*STDERR = IO::Tee->new(\*STDERR2, ">$logfile") or
die "Failed to tee to aliased STDERR and '$logfile': $!";
print(STDERR "This is a test\n");
Any suggestions? Thanks in advance.
UPDATE: I found the problem. Line 9 should be:
*STDERR = IO::Tee->new(\*STDERR2, $logfile)
I thought I had tried that also, but apparently not!