[fpc-pascal] Pipe buffering, accessing C-style stdin/stdout

Ingemar Ragnemalm ingemar at ragnemalm.se
Sun Apr 1 21:12:21 CEST 2007


Dear list,

I have been struggling for quite a while (that is weeks) to get proper 
pipe communication with a sublaunched program, using TProcess or 
straight pipe/fork/exec calls. This is under Mac OSX, but the problem 
should be similar under any Unix.

The problem is the buffering. Using stdio, the data is stalled until the 
stdio buffers are full. This is a big problem. Two-way communication is 
impossible, and the user feedback is delayed.

After a lot of googling and experimenting, I think I have managed to 
make it work, but only in C code, and I want it to run in Pascal. The 
key to make it work in C was to call setvbuf at the right time, to set 
the buffering mode for stdin/stdout. The problem with FPC is that I 
can't find any straightforward way to either get PFile-style 
stdin/stdout from the Text-style input/output (surely there is a 
connection?), or get the C globals.

I have searched through the fpc and Lazarus sources after the 
definitions and possible solutions, tried all ways I can find, but have 
not succeeded yet. But surely someone else has ran into this problem?

Shouldn't simply TProcess have unbuffered or line-buffering as default?


/Ingemar




More information about the fpc-pascal mailing list