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!


In reply to How to tee STDERR on Windows by freonpsandoz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.