in reply to STDERR and STDOUT

That won't be easy to do. You're suffering from buffering, but not in your program, but in the program you are calling. Typically, STDOUT is buffered, while STDERR isn't. Only when STDOUT is redirected to a terminal, it's flushed when a newline is emitted. But you don't call it from a terminal - you're capturing the output, so the output is buffered, and appears later than the unbuffered STDERR.

If you can tell the called program to run output unbuffered, than that's your easiest option.

Perl --((8:>*

Replies are listed 'Best First'.
Re^2: STDERR and STDOUT
by Aristotle (Chancellor) on Nov 18, 2005 at 14:12 UTC

    If asking it nicely is not possible, you can still run the program on a pseudo-TTY to make it behave as it would on the console. It’s not much fun for such a simple task though, even if IO::Pty will do the dirty work for you.

    Makeshifts last the longest.