Mike

Many thanks for your reply and sorry for taking a while to respond...

<confusion>
Er, yes, that does work. Ok, then. Given that open(STDERR, '|-'); was actually the first thing I tried and it did not work for me, I obviously did something stupid. It turns out that I did two stupid things. The first was that I did not try all the alternatives against a simple test case. The second was that I did not read the source of P::RD carefully enough.

...Time passes while Kevin reads P::RD properly this time...

The output I am concerned about is actually written to a format, not directly to STDERR. Why does this matter? Because the format is opened by dup(2)ing STDERR, which gives a fresh file descriptor. So, I can sit there in the child waiting for output on STDERR until I am blue in the face and it will not get me anywhere.
</confusion>

So, what now? It does not seem as though I can open an output filter, since I do not know to which file descriptor I should listen. Perhaps I could spin around all of them, but that sounds pretty obscure.

How about tie'ing the format to a suitable class? Well, this partially works. As it happens, P::RD both prints and writes to the format. The prints come through fine but the writes do not. It seems as though writes to a format cannot be tied. See the example code below:

use strict; use warnings; package Log::OPG::Info; use Tie::Handle; use base qw(Tie::StdHandle); sub WRITE { print "Good\n"; } package main; format STDERR = Bad . tie *STDERR, 'Log::OPG::Info'; print STDERR ''; write STDERR;

Whereas I hope for the output

Good Good
I actually get
Good Bad

So, either I am missing something obvious, or the follow-up question is:

"How does one tie writes to a format?"

Cheers
Kevin

P.S. I faintly remember that it is possible to name individual slots in hash table entries, along the lines of $::slot{SCALAR} and $::slot{FORMAT}. Perhaps that might form the basis for a solution, but the details escape me.


In reply to Re: Re: Filtering my own stderr by Anonymous Monk
in thread Filtering my own stderr by ruscoekm

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.