无视猛砸pipefail错误code 141 [英] Ignoring Bash pipefail for error code 141

查看:270
本文介绍了无视猛砸pipefail错误code 141的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(通过设置-o pipefail )允许,如果非脚本失败设置的bash pipefail 选项落入零误差,那里是一个非零的错误在管道的任何步骤。

Setting the bash pipefail option (via set -o pipefail) allows the script to fail if a non-zero error is caught where there is a non-zero error in any step of a pipe.

不过,我们正在运行到 SIGPIPE 错误(错误code 141),其中数据写入不再存在的管道。

However, we are running into SIGPIPE errors (error code 141), where data is written to a pipe that no longer exists.

有没有一种方法来设置的bash忽略 SIGPIPE 的错误,或者是有编写错误处理程序将处理所有的错误状态codeS而是一种方法,说,0和141?

Is there a way to set bash to ignore SIGPIPE errors, or is there an approach to writing an error handler that will handle all error status codes but, say, 0 and 141?

例如,在Python中,我们可以添加:

For instance, in Python, we can add:

signal.signal(signal.SIGPIPE, signal.SIG_DFL) 

应用默认行为 SIGPIPE 错误:忽略它们(见的http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-06/3823.html).

to apply the default behavior to SIGPIPE errors: ignoring them (cf. http://coding.derkeiler.com/Archive/Python/comp.lang.python/2004-06/3823.html).

有一些类似的选项可在bash?

Is there some similar option available in bash?

推荐答案

陷阱命令,可以指定命令遇到的信号时运行。要忽略的信号,传递空字符串:

The trap command lets you specify a command to run when encountering a signal. To ignore a signal, pass the empty string:

trap '' PIPE

这篇关于无视猛砸pipefail错误code 141的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆