【发布时间】:2013-06-12 09:08:30
【问题描述】:
在 bash 中,命名管道可以使用 cat > mypipe 保持打开状态。这怎么能在python中完成?这是我目前所拥有的:
import subprocess
import os
if not os.path.exists("/tmp/mypipe"):
os.mkfifo("/tmp/mypipe")
【问题讨论】:
标签: python pipe named-pipes
在 bash 中,命名管道可以使用 cat > mypipe 保持打开状态。这怎么能在python中完成?这是我目前所拥有的:
import subprocess
import os
if not os.path.exists("/tmp/mypipe"):
os.mkfifo("/tmp/mypipe")
【问题讨论】:
标签: python pipe named-pipes
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)
【讨论】: