Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How can I redirect the output of a command such that both stdout and stderr gets logged in a file, AND I still want stderr to appear as output.
I also don't want to use bash for doing this. Is there such a way?
这很容易:
$ ( ./command.sh >> log ) 2>&1 | tee -a log
您将命令的标准输出写入log子外壳中的文件;比您将 stderr 写入管道;然后,我的方法是tee将其保存到 并将其log复制到控制台。
log
tee
使用示例:
$ cat command.sh #!/bin/sh echo out echo err > /dev/stderr $ ( ./command.sh >> log ) 2>&1 | tee -a log err $ cat log out err