如何将stderr重定向到整个管道的文件? [英] How to redirect stderr to a file for the whole pipe?
本文介绍了如何将stderr重定向到整个管道的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行这样的命令:
I am running a command like this:
mycmd1 | mycmd2 | mycmd3 | lp
是否有一种方法可以将stderr重定向到整个管道的文件,而不是对每个命令重复执行该操作?
Is there a way to redirect stderr to a file for the whole pipe instead of repeating it for each command?
也就是说,我宁愿避免这样做:
That is to say, I'd rather avoid doing this:
mycmd1 2>/myfile | mycmd2 2>/myfile | mycmd3 2>/myfile | lp 2>/myfile
推荐答案
任意
{ mycmd1 | mycmd2 | mycmd3 | lp; } 2>> logfile
或
( mycmd1 | mycmd2 | mycmd3 | lp ) 2>> logfile
将起作用. (根据外壳程序的不同,第一个版本的启动时间可能会稍短(〜1ms)).
will work. (The first version might be have a slightly faster (~1ms) startup time depending on the shell).
这篇关于如何将stderr重定向到整个管道的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文