IOError: [Errno 32] Broken pipe when piping: `prog.py | othercmd` IOError:在管道传输时出现[Errno 32] Broken pipe错误:`prog.py | othercmd`

9 浏览
0 Comments

IOError: [Errno 32] Broken pipe when piping: `prog.py | othercmd` IOError:在管道传输时出现[Errno 32] Broken pipe错误:`prog.py | othercmd`

我有一个非常简单的Python 3脚本:

f1 = open('a.txt', 'r')
print(f1.readlines())
f2 = open('b.txt', 'r')
print(f2.readlines())
f3 = open('c.txt', 'r')
print(f3.readlines())
f4 = open('d.txt', 'r')
print(f4.readlines())
f1.close()
f2.close()
f3.close()
f4.close()

但它总是显示:

IOError: [Errno 32] Broken pipe

我在互联网上看到了所有复杂的修复方法,但我直接复制了这段代码,所以我认为问题出在代码上,而不是Python的SIGPIPE。

我正在重定向输出,所以如果上面的脚本被命名为"open.py",那么我运行的命令将是:

open.py | othercommand

0