My aim is to capture the stdout and stderr from an exec()ed program, but not just interleaved into one stream. So I'm doing something like:
The problem is that if some_application buffers stdout, I don't seem to get *anything* back on READOUT. I only get stuff back when I print heaps (ie. exceeding the 4096 buffer I guess). Newlines don't force a buffer flush. If I set $|=1 in some_application, everything is fine!pipe READOUT, WRITEOUT; if (my $pid = fork) { close(WRITEOUT); # try to read from READOUT, which fails. } else { close(STDERR); close(STDOUT); open(STDOUT, ">&WRITEOUT"); # This next line makes no difference. select(STDOUT); $|=1; exec("some_application"); }
This is no good though, because I might not have access to the source if some_application is not a perl app. And I don't want to have to modify things like that. So what has failed here?
I've spent way too much time on this - but it's bugging me. It's as if I need a way to force some_application to not set its stdout to buffered mode, or in the parent block above, somehow post exec() set some_application's stdout to non-buffered.
Any hints?
--
Ash OS durbatulk, ash OS gimbatul,
Ash OS thrakatulk, agh burzum-ishi krimpatul!
Uzg-Microsoft-ishi amal fauthut burguuli.
Update 2002-04-08 by mirod: changed <pre> tags to <code> tags
In reply to Pipe, fork, exec and red-hot pokers. by hagus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |