在将stdout和stderr写入日志文件时是否可以仅将stdout打印到屏幕上?

问题描述 投票:1回答:1

我知道可以将两者都重定向到特定文件:

./command 1> out.log 2> err.log

./command 1>test.log 2>&1

将两者都写入文件。但是我不知道在只打印两个文件时都将它们写入同一文件的方法。 tee不是很有用,因为它同时打印两个文件描述符。

bash io io-redirection
1个回答
1
投票

使用tee将标准输出写到一个文件而又写到另一个文件很简单:

{ cmd | tee stdout.log; } &> both.log

将标准错误写给一个人,并且都写给另一个人比较棘手。

{ foo 2>&1 1>&3 | tee stderr.log ; } 3>&1 | tee both.log > /dev/null
© www.soinside.com 2019 - 2024. All rights reserved.