2013-06-12 41 views
0

在bash中,命名管道可以使用cat > mypipe保持打開狀態。這怎麼能在Python中完成?這是我到目前爲止:Python保持命名管道開放

import subprocess 
import os 

if not os.path.exists("/tmp/mypipe"): 
    os.mkfifo("/tmp/mypipe") 

回答

1
import os 
import subprocess 

path = '/tmp/mypipe' 
if not os.path.exists(path): 
    os.mkfifo(path) 

with open(path, 'w') as f: 
    subprocess.call(['cat'], stdout=f)