[Shell] BrokenPipeError: [Errno 32] Broken pipe1

BrokenPipeError: 管道重定向导致 stdout 错误
具体错误信息如下:
Exception ignored in: <_io.TextIOWrapper name=’’ mode=‘w’ encoding=‘utf-8’> BrokenPipeError: [Errno 32] Broken pipe
1
导致出问题的地方:

if eval "$diff_command" | $CLANG_FORMAT_DIFF_SCRIPT -p1 | grep -q . &>/dev/null; then

若 $CLANG_FORMAT_DIFF_SCRIPT 中打印没有执行完时,外面的命令直接重定向或者关闭终端会发生以下错误

Traceback (most recent call last):
  File "/home/xxx/clang-format-diff.py", line 384, in 
    main()
  File "/home/xxx/clang-format-diff.py", line 373, in main
    sys.stdout.write(diff_string)
BrokenPipeError: [Errno 32] Broken pipe

解决方法
不使用管道

diff_result=$(eval "$diff_command")
clang_format_diff_result=$($CLANG_FORMAT_DIFF_SCRIPT -p1 <<< "$diff_result")
if [ -n "$clang_format_diff_result" ]; then

你可能感兴趣的:(Shell,用法与编程,shell)