Reputation: 3117
The win32pipe.PeekNamedPipe gets the arguments pyHandle(read handle) and a buf size . The pyHandles are returned by win32pipe.createPipe() which gives me a read and write handle to the pipes.
Now, assume I have got the handle/integer value of the read handle of this pipe to another process. I want to read the data on the handle using peekNamedPipe method by passing in a pyHandle.
I read elsewhere that functions tat accept pyHandles will also accept the int values, but in this case it does not , it gives me an error saying invalid handle when I try to pass the int.
Is there a way I can create a pyHandle Object with the integer that I have ?
Upvotes: 0
Views: 1423
Reputation: 12135
I know very little about Python or pyHandles, but from your description it sounds as if a pyHandle is a thin wrapper around a Win32 HANDLE, in this case a HANDLE to a Pipe object.
HANDLEs in Windows are obtained from the operating system as the result of calling a variety of Win32 API functions, including CreatePipe. Most HANDLEs have process-affinity, and so can only be used by the process which acquired them.
In Win32, if you have a HANDLE to an object, and want to pass a reference to that object to another process, you have to explicitly call the API DuplicateHandle to ask the operating system to give you a handle which will work in the other process.
So if you can find a way to call DuplicateHandle
using the numeric value from your original pyHandle, you should be able to transform it into a different handle value which can be used in the other process.
Upvotes: 1