将stdout和stderr重定向到文件,将stderr重定向到stdout [英] Redirect stdout and stderr to file and stderr to stdout
问题描述
以下将stdout写入日志文件并打印stderr:
The following writes stdout to a logfile and prints stderr:
bash script.sh >> out.log
这再次将stdout和stderr写入日志文件:
This again writes both stdout and stderr to a logfile:
bash script.sh >> out.log 2>&1
如何组合这两个功能,以便stdout和stderr
How to combine both features, so that stdout and stderr are logged to a file and stderr is emailed to my inbox?
推荐答案
bash script.sh 2>&1 >> out.log | tee -a out.log
首先,我将重新导向 stdout 文件和 stderr 文件和 stderr ( stdout <>
First, I'm redirecting stdout to file and stderr to stdout (stdout line gets to the out.log file and stderr to pipe).
tee
> stdout 和文件(与字母 T 相似)。因此,其次,我将 stderr 打印到 stdout 和 out.log 文件( -a
参数意味着追加)。
The tee
command prints stdin to both stdout and file (resemblance with the letter T). Thus second, I'm printing the original stderr to both stdout and the out.log file (the -a
argument means append).
这篇关于将stdout和stderr重定向到文件,将stderr重定向到stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!