Linux(os.mkfifo)
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 |
import errno import os FIFO_PATH = './mypipe' # create try: os.mkfifo(FIFO) except OSError as oe: if oe.errno != errno.EEXIST: raise # open fifo_w = open(FIFO_PATH, 'wb') fifo_r = open(FIFO_PATH, 'rb') # write fifo_w.write(data) # read data = fifo.read() # close fifo_w.close() fifo_r.close() |
Windows(win32pipe,win32file)
command
$ pip install pywin32
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import win32pipe, win32file, pywintypes # create fifo = win32pipe.CreateNamedPipe( r'\\.\pipe\mypipe', win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT, 1, 65536, 65536, 0, None) # connect win32pipe.ConnectNamedPipe(fifo, None) # write win32file.WriteFile(fifo, data) # read result, data = win32file.ReadFile(fifo, 65536, None) |