使用tee时获取exitcode

当使用tee时,程序的exitcode无法正常获取,比如a.out的exitcode为1,但是使用tee之后得到的为0。这时可以使用set -o pipefail,如下:

./a.out | tee
echo $? # 0

set -o pipefail
./a.out | tee
echo $? # 1



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • jinja.cpp:为什么我要手写一个 Jinja2 编译器
  • LLM Super Weight 实测:剪枝降智与量化思考
  • MNN支持Eagle3
  • LLM训练实战手册
  • MNN模型支持:Qwen3-VL