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 關注
- 574 瀏覽
添加回答
舉報