No such thing as a small change | |
PerlMonks |
How to change Open2 input bufferingby thecap (Initiate) |
on Oct 17, 2003 at 15:41 UTC ( [id://300044]=perlquestion: print w/replies, xml ) | Need Help?? |
thecap has asked for the wisdom of the Perl Monks concerning the following question:
I am using Open2 to run a C program that outputs a line with a timestamp in reply to each input line. The problem is that the reply lines are buffered together.
Desired results (happens when program is run from terminal or if C program calls fflush(stdout) after each printf):
Observed with Open2 and no fflush in the C program:
I believe the problem is that C program's libc tries to detect if stdout is connected to a terminal. If it is connected to a terminal it uses line buffering, otherwise it uses full buffering. How can I make the stdout of a program started with Open2 appear to be connected to a terminal? I do not want to change the source of the C program. I am using IO::Select to see if there is any output as the actual program I want to use will only sometimes produce output. I tried looking at the glibc-2.3.2 source to find how it decides what buffering to use on stdout, but could not work out how the line "./sysdeps/standalone/open.c: setvbuf( stdout, NULL, _IOLBF, BUFSIZ );" is called. Here is a strace dump of running the C program with Open2:
Here is a run with the same inputs from the shell:
Thank you for any ideas you may have to help me,
Back to
Seekers of Perl Wisdom
|
|