in reply to Re^2: Prepending a string to STDERR output, and logging STDOUT & STDERR synchronously to a file
in thread Prepending a string to STDERR output, and logging STDOUT & STDERR synchronously to a file
Please the <code> tags around your code. (It's custom to PerlMonks.) It makes it (more) readable, preserves whitespace, handles HTML escaping, wraps lines if needed, and provides a mechanism to view the code unwrapped.
One problem I see is that you use <FH> instead of sysread. See the warning at the bottom of the documentation for select.
Another problem I see if that it only prints "STDOUT: " or "STDERR: " for every chunk, not necessarily every line. You need to split on newlines what you get.
I never figured out the use of some methods in IO::Select. What's the use of can_read if you can't check for errors? The proper usage seems to be:
use IO::Select; $selector = IO::Select->new(); $selector->add(*CMD_ERR, *CMD_OUT); while ($selector->count()) { my ($readable, undef, $error) = IO::Select::select($selector, undef, $selector); $selector->remove($_) foreach @$error; foreach my $fh (@$readable) { ... } )
I don't know what you mean by "left hanging".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Prepending a string to STDERR output, and logging STDOUT & STDERR synchronously to a file
by OfficeLinebacker (Chaplain) on Apr 18, 2006 at 19:40 UTC | |
by ikegami (Patriarch) on Apr 18, 2006 at 19:41 UTC |