如果使用三通,如何检查出口? [英] How to check exit if used tee?

查看:16
本文介绍了如果使用三通,如何检查出口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 tee 将输出保存在如下文件中:

I try to use tee to save output in file like:

myapp | tee log.txt

但是我在检查退出时遇到了问题.之前的代码:

But I have a problem with checking of exit. Previous code:

myapp 
if [ $? -eq 0 ] 
then .....

但是$?将是发球台的出口!是否有可能捕获 myapp 的退出?谢谢.

But $? will be exit of tee! Does it possible catch exit of myapp? Thanks.

推荐答案

对于 bash,有一个方便的特殊数组:PIPESTATUS.myapp 的返回码将在 ${PIPESTATUS[0]} 中,以此类推.

For bash, there's a convenient special array: PIPESTATUS. The return code for myapp would be in ${PIPESTATUS[0]} and so on.

zsh 有一个大致相同的方法.

zsh has a roughly identical method.

在严格的 bourne shell 中还有一种更烦人、更笨拙的方法,您可以在 comp.unix.shell 常见问题解答.

There's also a rather more annoying, hacky way to do it in strict bourne shells that you can read about in the comp.unix.shell FAQ.

这篇关于如果使用三通,如何检查出口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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