Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
OK, I realize Log4Perl is a lot of work rewriting your scripts, but trust me, it's worth it. For a quick start, follow the easy_init directions, and just replace all your 'print "' with $log->info(), and all the warn or 'print STDERR' calls with $log->warn().

But, of course you would like to use as much of the existing script as possible. So, to address your current problem, try using \*STDOUT directly in the IO::Tee call. I've found odd behavior when I pass it as another variable, vs passing it as \*STDOUT and \*STDERR. Call multiplex with some sort of indicator instead of the reference (a string perhaps "STDOUT" or "STDERR"), and make separate calls to IO::Tee for each of these.

To debug this, try using the handles method of IO::Tee. Add a print join(' ', $tee->handles), "\n"; (taken from the perldocs) to your multiplex method to see what it's really producing. Compare the results of using the Handle reference, vs using \*STDOUT.

I know the above works, but making separate calls to IO::Tee is pretty ugly. This is untested, but you might try creating a new filehandle object pointing to STDOUT. Perhaps something like IO::File->new(\*STDOUT), or more basic, IO::Handle->new_from_fd(fileno(STDOUT),"w"). Pass the return value from one of these to multiplex instead of the reference to the glob.

~J


In reply to Re: Re: Multiplexing STDOUT and STDERR by jmanning2k
in thread Multiplexing STDOUT and STDERR by kilinrax

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-28 23:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found