博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tee stderr_如何使Tee仅在Linux中捕获stderr?
阅读量:2518 次
发布时间:2019-05-11

本文共 1062 字,大约阅读时间需要 3 分钟。

tee stderr

I would like to make tee catch the stderr and log it into a file.

我想让tee捕获stderr并将其记录到文件中。

A brute force method by let tee listen on both stderr and is okay like

让tee在stderr和上侦听的暴力方法是可以的

cmd 2>&1 | tee -a log

But how to make tee catch the stderr only?

但是如何使T恤只接住stderr?

You can make use of “process substitution” (>(...)) to creates a FIFO to catch the STDERR and pass it to tee.

您可以使用“进程替换”( >(...) )创建一个FIFO来捕获STDERR并将其传递给tee

Lets take an example t.sh:

让我们以t.sh为例:

#!/bin/bashecho hello1>&2 echo world

It works as expected:

它按预期工作:

$ ./t.sh helloworld$ ./t.sh >/dev/nullworld$ ./t.sh 2>/dev/nullhello

Now, let’s redirect the STDERR to tee:

现在,让我们将STDERR重定向到tee

$ ./t.sh 2> >(tee /tmp/log)hello$ worldcat /tmp/log world

tee prints to STDOUT by . Let’s make it to STDERR:

tee 打印到STDOUT。 让我们将其到STDERR:

$ ./t.sh 2> >(tee /tmp/log >&2)helloworld$ cat /tmp/log world

Verify it:

验证一下:

$ (./t.sh 2> >(tee /tmp/log >&2) ) >/dev/nullworld

The “world” is not to the STDOUT anymore.

“世界”不再属于STDOUT。

Answered by Eric Z Ma.
埃里克·马(Eric Z Ma)回答。

翻译自:

tee stderr

转载地址:http://mulwd.baihongyu.com/

你可能感兴趣的文章
codeforces Unusual Product
查看>>
hdu4348 - To the moon 可持久化线段树 区间修改 离线处理
查看>>
正则表达式的搜索和替换
查看>>
个人项目:WC
查看>>
地鼠的困境SSL1333 最大匹配
查看>>
flume+elasticsearch+kibana遇到的坑
查看>>
【MM系列】在SAP里查看数据的方法
查看>>
C#——winform
查看>>
CSS3 transform制作的漂亮的滚动式导航
查看>>
《小强升职记——时间管理故事书》读书笔记
查看>>
Alpha 冲刺(3/10)
查看>>
Kaldi中的Chain模型
查看>>
spring中的ResourceBundleMessageSource使用和测试示例
查看>>
css规范 - bem
查看>>
电梯调度程序的UI设计
查看>>
转自 zera php中extends和implements的区别
查看>>
Array.of使用实例
查看>>
【Luogu】P2498拯救小云公主(spfa)
查看>>
如何获取网站icon
查看>>
几种排序写法
查看>>