Skip to content

Instantly share code, notes, and snippets.

@Coronon
Last active October 3, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coronon/6c6ef55bdccefab18779a8cef2ec3c97 to your computer and use it in GitHub Desktop.
Save Coronon/6c6ef55bdccefab18779a8cef2ec3c97 to your computer and use it in GitHub Desktop.
Easy NamedPipe for Windows written in python3
import win32pipe, win32file
class PipeServer():
def __init__(self, pipeName):
self.pipe = win32pipe.CreateNamedPipe(
r'\\.\pipe\\'+pipeName,
win32pipe.PIPE_ACCESS_OUTBOUND,
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_READMODE_MESSAGE | win32pipe.PIPE_WAIT,
1, 65536, 65536,
0,
None)
#Careful, this blocks until a connection is established
def connect(self):
win32pipe.ConnectNamedPipe(self.pipe, None)
#Message without tailing '\n'
def write(self, message):
win32file.WriteFile(self.pipe, message.encode()+b'\n')
def close(self):
win32file.CloseHandle(self.pipe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment