Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Sat Sep 22 21:31:57 CEST 2001

On Sat, 22 Sep 2001, Thomas Schatzl wrote:

> From: "Andreas K. Foerster" <AKFoerster at AKFoerster.de>
> Subject: Re: [fpc-pascal]Filter
> The general idea is (if I am not completely mistaken, from memory):
> --- popen functionality
> *create unnamed pipe - you get two file handles, one for reading, one for
> writing
> *save old stdout + stdin
> *set stdout to write handle
> *(maybe) change read handle to be non-inheritable (to avoid inheritage of
> more file handles than necessary)
> *create + run the child process. It automatically inherits all inheritable
> handles by default afair (Win32)
> *(maybe) restore stdout in main program already at this point and close
> write handle. You don't need it anymore in the main process, the child
> process automatically gets a copy. This copy will be automatically closed on
> process exit.
> *return read handle to main program
> --- popen ends
> *in child program just write as usual to stdout (which is now one end of the
> pipe)
> *read data from read handle (other end of pipe) or set stdin to the read
> handle for more convenient access until child program finishes and no more
> data available.
> You may use some event synchronization functions to avoid waste of cpu time.
> Using threads might not prove a good idea with FPC.
> *close pipe handles left open
> *restore standard i/o handles in main program if applicable and not done yet
> See the MS docs for more information about pipes and process creation.

... or look at the TProcess code in the FCL, which does all this for
Windows&Linux. German users may want to buy the 5th issue of Toolbox; There
the complete TProcess component is presented for process control under


More information about the fpc-pascal mailing list