您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

IOError:[Errno 32]管道损坏:Python

IOError:[Errno 32]管道损坏:Python

我没有重现这个问题,但是也许这种方法可以解决这个问题:(逐行写入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

python 2022/1/1 18:47:22 有324人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶