我没有重现这个问题,但是也许这种方法可以解决这个问题:(逐行写入stdout
而不是使用print
)
import sys
with open('a.txt', 'r') as f1:
for line in f1:
sys.stdout.write(line)
你能抓住破损的管道吗?这将文件stdout
逐行写入,直到关闭管道为止。
import sys, errno
try:
with open('a.txt', 'r') as f1:
for line in f1:
sys.stdout.write(line)
except IOError as e:
if e.errno == errno.EPIPE:
# Handle error
您还需要确保othercommand
在管道变得太大之前正在从管道读取-https://unix.stackexchange.com/questions/11946/how-big-is-the-pipe- buffer