in reply to multiple programs sharing redirected STDERR

As long as you have line buffering, you should be OK.

see $| and IO::Handle::setvbuf If you use the default settings with syswrite you should be ok. If you are on a system where this does not work you can add an flock around the syswrite.

BEGIN { $SIG{'__WARN__'} = sub { syswrite STDERR, $_[0] } } warn "Warnings go to STDERR\n";

Update: added example.

-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re^2: multiple programs sharing redirected STDERR
by ff (Hermit) on Apr 26, 2005 at 18:21 UTC
    Thanks, though this leads to more questions:

    1. The documentation describes $| as working with the currently selected output channel. STDERR also counts as the currently selected output channel?

    2. Documentation for IO::Handle seems to say that
    # setvbuf is not available by default on Perls 5.8.0 and later.

    The pod for Handle.pm goes on to say that:

    WARNING: The IO::Handle::setvbuf() is not available by default on Perls 5.8.0 and later because setvbuf() is rather specific to using the stdio library, while Perl prefers the new perlio subsystem instead +.
    From my ActiveState documentation, it does not look like this is included.

    Also, it looks like I can't use garden variety warn calls with IO::Handle, I'll need to change these all to object references? I assume system errors for STDERR will magically know to write to the designated file?

        1. The documentation describes $| as working with the currently selected output channel. STDERR also counts as the currently selected output channel?

      I believe STDOUT is the default 'currently selected output channel'. See the description of 'select' in the Camel. (It's on page 210 of my very old version.)

      --
      tbone1, YAPS (Yet Another Perl Schlub)
      And remember, if he succeeds, so what.
      - Chick McGee