技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

python读写命名管道

apue里说匿名管道只能在父子进程里使用。如果两个没有关系的进程要通信,就只能使用命名管道,最简单的代码这里:

pwrite.py

import os

fd = os.open('pipetest',os.O_NONBLOCK | os.O_CREAT | os.O_RDWR)
os.write(fd,"hello")

 

pread.py

import os

fd = os.open('pipetest',os.O_RDONLY)
s = os.read(fd,5)
print s

posted on 2012-06-11 14:30  codestyle  阅读(4806)  评论(0编辑  收藏  举报