[fpc-pascal] Redirecting input to a child process
Anton Shepelev
anton.txt at gmail.com
Mon May 9 12:21:10 CEST 2011
Ludo Brands:
> You can file a bug at http://bugs.freepascal.org/
OK.
> Dupicating handles isn't apparently the only solution. The
> msdn sample creates non-inheritable pipes and hands these
> handles simply over to createprocess, without duplicating.
There are two solutions, but only of them allows detection
of EOF.
On MSDN there are two examples. In this one:
http://msdn.microsoft.com/en-us/library/ms682499(v=vs.85).aspx
inheritable pipe handles are created using CreatePipe, just
as I was doing in my initial WinApi code and as TProcess is
doing. These pipes don't support the detection of EOF.
In this one:
http://support.microsoft.com/kb/190351/en-us?fr=1
non-inheritable pipes are created by CreatePipe, which are
then duplicated into inheritable ones using DuplicateHandle.
The duplicates are passed to CreateProcess, while the non-
inheritable originals are used by the parent process, allow-
ing it to issue EOF by closing them.
This is what made my WinApi code work with more.com.
> You want to pass inheritable handles if you want the child
> to have full control of the pipe, which apparently isn't
> needed for RW.
A handle must be inheritable in order to be passed from one
process to another. There are two ways to make it so:
1. Specify a flag in CreateProcess
2. Duplicate a non-inheritable handle using
DuplicateHandle
The first MSDN example goes the former way and second the
latter way.
Anton
More information about the fpc-pascal
mailing list