Redirection of standard Input by TProcess doesn't trigger EOF on the child process's side
Original Reporter info from Mantis: Ant_222
-
Reporter name: Anton Shepelev
Original Reporter info from Mantis: Ant_222
- Reporter name: Anton Shepelev
Description:
The TProcess class, to redirect standrd IO channels, uses the WinApi CreatePipe function to create pipes with inheritable handles, which do not support detection of EOF at the reading end when the writing-end handle has been closed. This feature makes it impossible to use TProcess to feed input to console programs expecting a EOF, whilst this is the standard behaviour of a command-line program.
The problem can be fixed by changing the way of pipe creation. Instead of creating inheritable pipes with CreatePipe (SECURITY_ATTRIBUTES.bInheritHandle = true) use it to create a pipe with non-inheritalbe handles, and then duplicate the handles into inheritable ones, which are to be passed to the CreateProcess function.
This way, the parent process will operate non-inheritable pipe handles using inheritalble ones only with CreateProcess, and the closing in the parent process of the write end of the input handle will issue an EOF on the reading end in the child process, which will allow it to properly terminate.
A Windows program reproducing the bug is attached.
The original post and discussion of the bug on the FPC mailing list:
http://lists.freepascal.org/lists/fpc-pascal/2011-May/028933.html
Of which the most important posts are:
http://lists.freepascal.org/lists/fpc-pascal/2011-May/028955.html
http://lists.freepascal.org/lists/fpc-pascal/2011-May/028965.html
Mantis conversion info:
- Mantis ID: 19325
- OS: Windows XP
- Version: 2.4.2
- Fixed in version: 2.6.0
- Fixed in revision: 17518 (#fd660355)