将stdout和stderr重定向到文件,将stderr重定向到stdout [英] Redirect stdout and stderr to file and stderr to stdout

查看:784
本文介绍了将stdout和stderr重定向到文件,将stderr重定向到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屋!

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