【发布时间】:2010-08-11 08:38:25
【问题描述】:
我希望能够使用Popen.communicate 并将标准输出记录到文件中(除了从communicate() 返回。
这正是我想要的——但这真的是个好主意吗?
cat_task = subprocess.Popen(["cat"], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
tee_task = subprocess.Popen(["tee", "-a", "/tmp/logcmd"], stdin=cat_task.stdout,
stdout = subprocess.PIPE, close_fds=True)
cat_task.stdout = tee_task.stdout #since cat's stdout is consumed by tee, read from tee.
cat_task.communicate("hello there")
('hello there', None)
这方面的任何问题,看看通信的 impl 看起来不错。但是有更好的方法吗?
【问题讨论】:
标签: python subprocess popen