Created
March 17, 2017 18:01
-
-
Save AstraLuma/0a2dd66e53c61cc362200fa988da8169 to your computer and use it in GitHub Desktop.
Testing select-like with pipes on windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import os | |
import ctypes | |
import ctypes.wintypes | |
PeekNamedPipe = ctypes.windll.kernel32.PeekNamedPipe | |
PeekNamedPipe.restype = ctypes.wintypes.BOOL | |
def try_peek(pipe, desc=''): | |
lpTotalBytesAvail = ctypes.wintypes.DWORD(0) | |
if isinstance(pipe, int): | |
pipe = ctypes.wintypes.HANDLE(pipe) | |
status = PeekNamedPipe( | |
pipe, | |
None, | |
ctypes.wintypes.DWORD(0), | |
None, | |
ctypes.byref(lpTotalBytesAvail), | |
None, | |
) | |
print(status, ctypes.GetLastError(), lpTotalBytesAvail) | |
pin = ctypes.wintypes.HANDLE(0) | |
pout = ctypes.wintypes.HANDLE(0) | |
ctypes.windll.kernel32.CreatePipe(ctypes.byref(pout), ctypes.byref(pin), None, 4096) | |
print(pin, pout) | |
try_peek(pout, 'CreatePipe:Open-Empty') | |
pin, pout = os.pipe() | |
print(pin, pout) | |
try_peek(pout, 'os.pipe:Open-Empty') | |
# p.side_in.write(b'Hello') | |
# try_peek(p, 'Open-HasData') | |
# print(repr(p.side_out.read(4000))) | |
# try_peek(p, 'Open-Empty') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment