hxcpp icon indicating copy to clipboard operation
hxcpp copied to clipboard

Reading from stdout of a process can hang on windows

Open Aidan63 opened this issue 4 years ago • 0 comments

Noticed that sometimes reading from the stdout of a process never returns on windows. Digging into things it seems like when the child process closes the stdout pipe isn't closed as it inherits from the parent process, so ReadFile will block forever as the child process has closed and there will never be more data in stdout.

I managed to work around this by setting HANDLE_FLAG_INHERIT to 0 using SetHandleInformation on the stdout pipe (https://stackoverflow.com/questions/54416116/readfile-does-not-return-while-reading-stdout-from-a-child-process-after-it-ends), but if I also apply that to the stderr pipe then reading from stdout will start to block again so I'm not sure what a proper fix would be.

Aidan63 avatar Nov 17 '21 17:11 Aidan63