如果用开球如何检查出口? [英] How to check exit if used tee?
本文介绍了如果用开球如何检查出口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用发球挽救输出像文件:
I try to use tee to save output in file like:
myapp | tee log.txt
不过,我有一个退出的检查问题。 previous code:
But I have a problem with checking of exit. Previous code:
myapp
if [ $? -eq 0 ]
then .....
但$?将T恤的出口!它是否MyApp的可能赶上出口?
谢谢你。
But $? will be exit of tee! Does it possible catch exit of myapp? Thanks.
推荐答案
有关bash中,有一个特殊的便利数组:PIPESTATUS。返回code为的myapp </ code>将是$ {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外壳,你可以在的的comp.unix.shell FAQ 。
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屋!
查看全文