3 回答
TA贡献1818条经验 获得超7个赞
尝试unbuffer哪个是expect包的一部分。您可能已经在系统上拥有它。
在你的情况下你会像这样使用它:
./a | unbuffer -p tee output.txt
(-p用于管道模式,其中unbuffer从stdin读取并将其传递给其余参数中的命令)
TA贡献1868条经验 获得超4个赞
你可以试试 stdbuf
$ stdbuf -o 0 ./a | tee output.txt
(大)手册页的一部分:
-i, --input=MODE adjust standard input stream buffering
-o, --output=MODE adjust standard output stream buffering
-e, --error=MODE adjust standard error stream buffering
If MODE is 'L' the corresponding stream will be line buffered.
This option is invalid with standard input.
If MODE is '0' the corresponding stream will be unbuffered.
Otherwise MODE is a number which may be followed by one of the following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
In this case the corresponding stream will be fully buffered with the buffer
size set to MODE bytes.
但要记住这一点:
NOTE: If COMMAND adjusts the buffering of its standard streams ('tee' does
for e.g.) then that will override corresponding settings changed by 'stdbuf'.
Also some filters (like 'dd' and 'cat' etc.) dont use streams for I/O,
and are thus unaffected by 'stdbuf' settings.
你没在运行stdbuf上tee,你运行它a,所以这应该不会影响你,除非你设置的缓冲a的溪流a的源头“。
另外,stdbuf是不是 POSIX,但GNU-的coreutils的一部分。
TA贡献1799条经验 获得超9个赞
您也可以尝试使用命令在伪终端中执行script命令(这应该强制执行到管道的行缓冲输出)!
script -q /dev/null ./a | tee output.txt # Mac OS X, FreeBSD
script -c "./a" /dev/null | tee output.txt # Linux
请注意,该script命令不会传播回包装命令的退出状态。
- 3 回答
- 0 关注
- 518 浏览
添加回答
举报