我尝试使用以下命令在终端中显示命名管道:
tail -f textFile | cut -d " " -f 3- | sed -e "s/a/g&g/"
由于某种原因,这不会产生任何输出。
如果删除 -f ,它确实会按预期工作:
tail textFile | cut -d " " -f 3- | sed -e "s/a/g&g/"
或者删除 cut 语句:
tail -f textFile | sed -e "s/a/g&g/"
或者删除 sed 语句:
tail -f textFile | cut -d " " -f 3-
只有当这三件事同时存在时,它才会突然不再产生任何输出。 sed 和 cut 的顺序没有区别。所有这些使我很难责怪这些程序中任何一个或一对的输入或输出缓冲行为。
获得所需功能的可能解决方案是while read line
结构,但如果可能的话,我想避免为每一行初始化命令。
我在想要过滤的 ping 命令中遇到了类似的情况。
以下网页似乎解释了问题所在(stdio 缓冲)http://www.pixelbeat.org/programming/stdio_buffering/ http://www.pixelbeat.org/programming/stdio_buffering/
该网站指出了一个解决方案,其中涉及使用“stdbuf”命令禁用缓冲
tail -f filename | stdbuf -o0 cut -d " " -f 3- | sed -e "s/a/g&g/"
上面的内容对我来说效果很好,删除“stdbuf -o0”会导致不显示任何输出。
>stdbuf --help
Usage: stdbuf OPTION... COMMAND
Run COMMAND, with modified buffering operations for its standard streams.
Mandatory arguments to long options are mandatory for short options too.
-i, --input=MODE adjust standard input stream buffering
-o, --output=MODE adjust standard output stream buffering
-e, --error=MODE adjust standard error stream buffering
--help display this help and exit
--version output version information and exit
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)