What's the correct way to use win32file.ReadFile to get the output from a pipe?

时光怂恿深爱的人放手 提交于 2019-12-04 18:56:39

For error codes, try winerror.ERROR_MORE_DATA and winerror.ERROR_IO_PENDING

My interpretation of the ActiveState docs is the same as yours. It sounds like the wrapper works slightly differently than the native API. Sorry I haven't actually tried this.

Consider using subprocess to launch the process. It will give you a set of file-like objects that you can use to talk with the other app.

The .terminate() method of the Popen object will allow you to terminate the process if you are running 2.6+.

note that ReadFile is defined as:

(int, string) = ReadFile(hFile, buffer/bufSize , overlapped)

where...

hFile = PyHANDLE

which is any windows handle (can be file, process, thread...)

buffer/bufSize = PyOVERLAPPEDReadBuffer

which, according to documentation automatically allocates contents of hFile regardless if it overlaps or not.

overlapped=None [=PyOVERLAPPED]

you can allocate an additional object to take any extra data, beyond the overlapped (buffer/bufSize) if you wish, but by default this is NULL.

So - you can basically call ReadFile like:

ReadFile(child_stdout_r, 0, None)

and the object you assign it to will contain the full contents of the file handle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!