将STDOUT重定向到新窗口,将STDERR重定向到相同的新窗口,同时还将日志文件重定向 [英] Redirect STDOUT to new window, STDERR to same new window and also a log file
本文介绍了将STDOUT重定向到新窗口,将STDERR重定向到相同的新窗口,同时还将日志文件重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在bash脚本中有一个漫长的过程(很多过程中的一个),因此我正在尝试将所有输出发送到一个单独的窗口进行监视,并将任何错误记录到 errorlog.txt 中. 例如:
rsync -vahPz foo@bar:/bigfolder/ ./ >> /dev/pts/4 2>> errorlog.txt
问题是上面的内容没有在单独的窗口中显示任何错误.
是否可以将错误重定向到/dev/pts/4
和 errorlog.txt 的单独窗口中,同时仍将正常输出重定向到/dev/pts/4
? /p>
类似的东西:
rsyncblah >> /dev/pts/4 2>> errorlog.txt && /dev/pts/4
解决方案
您可以将tee
与 解决方案
You can use tee
with process substitution, like this:
your_cmd 1> >(tee -a /dev/pts/2 >> out.log) 2> >(tee -a /dev/pts/2 >> err.log)
Alternatively, you can use the process substitution only for stderr - because it is needed - and redirect stdout, just as normal, through a pipe:
your_cmd 2> >(tee -a /dev/pts/2 >> err.log) | tee -a /dev/pts/2 >> out.log
这篇关于将STDOUT重定向到新窗口,将STDERR重定向到相同的新窗口,同时还将日志文件重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文