runInteractiveProcess and buffering

It looks like my problem has to do with buffering, but I don't know how to solve it. main :: IO () main = do (inp,out,err,pid) <- runInteractiveProcess "aseqdump" ["-p", "72:0"] Nothing Nothing hSetBuffering out NoBuffering hGetBuffering out >>= print hGetLine out >>= putStrLn return () The data of 'out' seems to be buffered, because 'aseqdump' must produce many lines until even the first one is returned by 'hGetLine' and printed by 'putStrLn'. I tried to disable buffering for 'out' and indeed 'NoBuffering' is printed to the terminal, but the output from 'aseqdump' is still deferred.

On 10/12/07, Henning Thielemann
The data of 'out' seems to be buffered, because 'aseqdump' must produce many lines until even the first one is returned by 'hGetLine' and printed by 'putStrLn'. I tried to disable buffering for 'out' and indeed 'NoBuffering' is printed to the terminal, but the output from 'aseqdump' is still deferred.
[I suspect this is a job for haskell-cafe@, anyway]
Are you sure that you aseqdump isn't buffering itself? The standard C
libraries will buffer output at the line level at least, and are free
to buffer much more than that if they think that the output is not to
a terminal.
Try building this code:
#include

On Fri, 12 Oct 2007, Adam Langley wrote:
On 10/12/07, Henning Thielemann
wrote: The data of 'out' seems to be buffered, because 'aseqdump' must produce many lines until even the first one is returned by 'hGetLine' and printed by 'putStrLn'. I tried to disable buffering for 'out' and indeed 'NoBuffering' is printed to the terminal, but the output from 'aseqdump' is still deferred.
[I suspect this is a job for haskell-cafe@, anyway]
Are you sure that you aseqdump isn't buffering itself?
I'm not sure, I only see that it works when started in a terminal. However if I pipe it to 'less' then the output is deferred for a while. This seems to indicate that the C program actually buffers itself. :-(
The standard C libraries will buffer output at the line level at least, and are free to buffer much more than that if they think that the output is not to a terminal.
Is this decision done automatically by C's standard library or must the C programmer do this manually? I couldn't find such a switch in the C program.

On 10/13/07, Henning Thielemann
Is this decision done automatically by C's standard library or must the C programmer do this manually? I couldn't find such a switch in the C program.
I believe that glibc fstat's FD 1 to find out if stdout is a terminal and sets its buffering up accordingly. The solution is to call fflush(stdout) at the correct places in the C code, or to force the buffering explicitly at the beginning of the program (see man setbuf). AGL -- Adam Langley agl@imperialviolet.org http://www.imperialviolet.org 650-283-9641
participants (2)
-
Adam Langley
-
Henning Thielemann