如何将 stdout 和 stderr 都重定向到文件 [英] How to redirect both stdout and stderr to a file

查看:49
本文介绍了如何将 stdout 和 stderr 都重定向到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 bash 脚本,它为命令的执行创建一个日志文件

I am running a bash script that creates a log file for the execution of the command

我使用以下内容

Command1 >> log_file
Command2 >> log_file

这只会发送标准输出,而不是终端上出现的标准错误.

This only sends the standard output and not the standard error which appears on the terminal.

我可以将 stderr 和 stdout 都记录到一个文件中吗?

Can I log both the stderr and stdout logged to a file?

推荐答案

如果你想登录到同一个文件:

If you want to log to the same file:

command1 >> log_file 2>&1

如果你想要不同的文件:

If you want different files:

command1 >> log_file 2>> err_file

这篇关于如何将 stdout 和 stderr 都重定向到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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