thecap has asked for the wisdom of the Perl Monks concerning the following question:
Desired results (happens when program is run from terminal or if C program calls fflush(stdout) after each printf):
Input1 time(): Output1 END time(): exit
Observed with Open2 and no fflush in the C program:
Input1 END time(): Output1 time(): exit
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:
read(0, "Input1\n", 4096) = 7 time(NULL) = 1066404185 read(0, "END\n", 4096) = 4 time(NULL) = 1066404190 write(1, "1066404185: \"Input1\"\n1066404190:"..., 38) = 38
Here is a run with the same inputs from the shell:
read(0, "Input1\n", 1024) = 7 time(NULL) = 1066404693 write(1, "1066404693: \"Input1\"\n", 21) = 21 read(0, "END\n", 1024) = 4 time(NULL) = 1066404697 write(1, "1066404697: exit\n", 17) = 17
Thank you for any ideas you may have to help me,
Tom
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to change Open2 input buffering (fix C RTL!)
by tye (Sage) on Oct 17, 2003 at 16:05 UTC | |
|
Re: How to change Open2 input buffering
by ptkdb (Monk) on Oct 17, 2003 at 16:34 UTC | |
|
Re: How to change Open2 input buffering
by sgifford (Prior) on Oct 17, 2003 at 20:14 UTC | |
by thecap (Initiate) on Oct 19, 2003 at 19:45 UTC | |
by sgifford (Prior) on Oct 20, 2003 at 03:53 UTC | |
by thecap (Initiate) on Feb 02, 2004 at 21:41 UTC |