Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Printing both to console and File

by 1nickt (Abbot)
on Apr 17, 2017 at 11:56 UTC ( #1188130=note: print w/replies, xml ) Need Help??

in reply to Printing both to console and File

The doc for IO::Tee indicates (unsurprisingly) that you need to pass two filehandles to the constructor, not construct two instances:

use IO::Tee; $tee = IO::Tee->new($handle1, $handle2); print $tee "foo", "bar";

For another approach see Log::Any, Log::Any::Adapter, Log::Any::Adapter::Dispatch.

Hope this helps!

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Printing both to console and File
by perluser455 (Initiate) on May 17, 2017 at 10:15 UTC
    Thanks for the reply, but Can you Please let me know how to pass stdout/stderr to filehandles when declared as use IO::Tee; $tee = IO::Tee->new($handle1, $handle2);

      It so happens that the example that contains the answer to your question is in the example section of IO::Tee's documentation.

      Edit: wait, you already use the \*STDOUT notation in your OP, I must be misunderstanding your question.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1188130]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2019-01-16 02:03 GMT
Find Nodes?
    Voting Booth?
    After Perl5, I'm mostly interested in:

    Results (274 votes). Check out past polls.