[fpc-pascal] TProcess on windows: incompatibility between poUsePipes and InheritHandles:=false

Luca Olivetti luca at ventoso.org
Tue Mar 11 19:43:23 CET 2014


El 11/03/14 19:17, Sven Barth ha escrit:
> On 11.03.2014 17:18, Luca Olivetti wrote:
>> In order to use poUsePipes, InheritHandles must be true
>> (see
>> http://msdn.microsoft.com/en-us/library/windows/desktop/ms686331%28v=vs.85%29.aspx)
>>
>> This is a limitation of the windows api, but I wonder if is there a
>> workaround to avoid inheriting other handles.
> [snip]
>> My current workaround is to terminate the process before trying to
>> destroy the thread, and that works, but I wonder if having unneeded
>> handles in a child process could have other unintended consequences, so
>> I'd like to know if is there a better workaround that allows to capture
>> stdout/stderr while at the same time avoiding inheriting other handles.
>> Possibly in a "generic" way, so that I don't need to have knowledge of
>> which handles are currently opened.
> 
> I have no explicit solution for you, but a few links that I hope can
> help you further:
> 
> http://blogs.msdn.com/b/oldnewthing/archive/2011/12/16/10248328.aspx

What surprises me is that it says that handles by default are
non-inheritable, that you have to explicitly set bInheritHandle to true
in a SECURITY_ATTRIBUTES parameter when creating the handle.
Yet, it seems that the socket is inherited even if there is no
security_attributes/bInheritHandle anywhere in synapse code.
Either that or the cause of what I observe is something else.

Note that previously I had a similar problem, see
http://bugs.freepascal.org/view.php?id=22271#c65861
but in that case I didn't need to capture stdout/stderr of the spawned
process, so setting InheritHandles to false solved it.

Bye
-- 
Luca



More information about the fpc-pascal mailing list