-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe_client.py
47 lines (30 loc) · 925 Bytes
/
pipe_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import win32file
bufferSize = 4096
def ConnectPipe(name):
handle = win32file.CreateFile(
'\\\\.\\pipe\\' + name,
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
0,
None,
win32file.OPEN_EXISTING,
0,
None)
return handle
def Read(pipe):
win32file.SetFilePointer(pipe, 0, win32file.FILE_BEGIN)
result, data = win32file.ReadFile(pipe, bufferSize, None)
buf = data
while len(data) == bufferSize:
result, data = win32file.ReadFile(pipe, bufferSize, None)
buf += data
return buf
def Write(pipe, data):
win32file.WriteFile(pipe, data)
pipe = ConnectPipe("Foo")
data = Read(pipe)
Write(pipe, b"hello from the other side")
print(data)
input("Done")
#reference
# https://stackoverflow.com/questions/48542644/python-and-windows-named-pipes
# https://stackoverflow.com/questions/29910861/python-read-file-using-win32file-readfile