将stderr和stdout重定向到Bash中的单独文件? [英] Redirect stderr and stdout to separate files in Bash?
本文介绍了将stderr和stdout重定向到Bash中的单独文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下方法将stdout
和stderr
重定向到单独的文件:
I am able to redirect stdout
and stderr
to separate files using:
dir >> out 2>> error
或stderror
和stdout
一起使用以下单个文件:
or stderror
and stdout
together to a single file using:
dir >> consolidate 2>&1
我该如何一起做(找出错误,一次合并文件)?
How can I do this together (get out, error, consolidate files at a time)?
推荐答案
您可以尝试以下方法:
(command > >(tee out.txt) 2> >(tee error.txt >&2)) &> consol.txt
测试:
$ ls
f
$ ls g*
ls: cannot access g*: No such file or directory
$ (ls g f > >(tee out.txt) 2> >(tee error.txt >&2)) &> consol.txt
$ cat out.txt
f
$ cat error.txt
ls: cannot access g: No such file or directory
$ cat consol.txt
f
ls: cannot access g: No such file or directory
这篇关于将stderr和stdout重定向到Bash中的单独文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文