[fpc-devel] StdOut capture for FPC RTL

Thaddy thaddy at thaddy.com
Thu Nov 25 01:32:48 CET 2010

On 24-11-2010 21:32, Michael Van Canneyt wrote:
> On Wed, 24 Nov 2010, Anton Kavalenka wrote: Get stdout handle 
> (duplicate it under linux),
>> create pipe,
>> replace the stdout (keeping the old stdout) for current process with 
>> write handle of pipe,
>> There are following problems with FPC
>> Under Windows: I have to call rewrite(output) for every thread which 
>> wants to use  new (captured) stdout
>> So the questions:
>> How to force all the threads of process and all DLLs write into same 
>> captured stdout?
> There is no way that I know of to avoid the rewrite(), since the file 
> descriptor records for Input, Output and StdErr are threadvars. And 
> the threadvars must be initialized on thread start.
>> How to revert stdout back (stop capturing)?
> Close and reopen using the standard filedescriptors ?
> Michael.
You can write a "classic" pascal textfile device driver and assign  
directly to the global TEXT variables Input, Output and ErrOutput.
Don't know is this is threadsafe, though.
I have some code by Peter Below on archive for that, that also works on 
FPC win. The implementation part of that unit can be adapted for nixen.
the file is called streamio.pas and can be easily found on the codegear 
website, but I will be happy to send it to you if you want by email.

More information about the fpc-devel mailing list