+ -
当前位置:首页 → 问答吧 → 有什么方法能用内存模拟文件

有什么方法能用内存模拟文件

时间:2010-12-23

来源:互联网

我在用subprocess,想用管道的效果
官方代码
  1. output=`dmesg | grep hda`
  2. ==>
  3. p1 = Popen(["dmesg"], stdout=PIPE)
  4. p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
  5. output = p2.communicate()[0]
复制代码
我想自己生成p1.stdout这个效果,我用了stringio,但是报错了,说stringio没有 fileno 这个方法

怎么完全模拟文件的效果呢?或者有什么方法能解决这个管道问题

作者: rockyaow   发布时间: 2010-12-23

回复 rockyaow

Popen("dmesg | grep hda", shell=True, stdout=PIPE)

作者: pastebt   发布时间: 2011-07-23