现在的位置: 首页 > 综合 > 正文

python读写命名管道

2012年02月21日 ⁄ 综合 ⁄ 共 221字 ⁄ 字号 评论关闭

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

抱歉!评论已关闭.