Shell 如何抑制终端输出和文本日志(tee)的I/O错误消息?
在我的程序中,程序会在几秒钟内将数据写入未连接的SSD(即写入空总线主机)。因此,在此期间,必须向终端输出一些I/O错误消息 除了将输出写入终端,我还需要记录程序的进度,但不需要记录I/O错误消息。以下是错误消息的快照:Shell 如何抑制终端输出和文本日志(tee)的I/O错误消息?,shell,io,Shell,Io,在我的程序中,程序会在几秒钟内将数据写入未连接的SSD(即写入空总线主机)。因此,在此期间,必须向终端输出一些I/O错误消息 除了将输出写入终端,我还需要记录程序的进度,但不需要记录I/O错误消息。以下是错误消息的快照: 5-1Input/output error Input/output error]! at block#[ ]! at block#[Input/output error WARNING: write errno[ 5 WARNING: write errno[ 5]! a
5-1Input/output error
Input/output error]! at block#[
]! at block#[Input/output error
WARNING: write errno[ 5
WARNING: write errno[ 5]! at block#[4773881Input/output error
Input/output error
146524727614844WARNING: write errno[ Input/output error
5]! at block#[], ret = ]! at block#[], ret = 13281183], ret = -1
WARNING: write errno[ Input/output errorWARNING: write errno[ 5]! at block#[234468], ret = -1-1
这是I/O错误消息的冰山一角。我的脚本文件名为run.sh
。我试着这样运行它:
$ run.sh | tee log.txt 2>&1
但这是无效的。。这个命令有什么问题吗?如果没有,会有什么问题?还有其他方法可以做到这一点吗?这里:
run.sh | tee log.txt 2>&1
您正在将tee的标准错误重定向到其标准输出。
但这看起来应该是您想要的(尽管不需要2>&
),因为tee不会生成错误消息
run.sh标准输出被发送到log.txt并显示在终端上
run.sh标准错误刚刚发送到终端
尝试:
…|grep-v“write errno”
?祝你好运,呃,不???你确定语法正确吗?
# run.sh output to log
# run.sh error to console
run.sh > log
# run.sh output to log and console
# run.sh error to console
run.sh | tee log
# run.sh error to same place as output
# run.sh output to console
run.sh 2>&1
# run.sh error to same place as output
# run.sh output to log
run.sh > log 2>&1
# run.sh error to same place as output
# run.sh output to console and log
run.sh 2>&1 | tee log