Flush Terminal Buffer?
The problem is that ./program -a asdf
's output gets buffered when run in the pipeline, and that any output it's going to sit within the buffer until this one gets full.
You can control a command's output buffering using stdbuf
; in particular, to run ./program -a asdf
with an unbuffered stdout
:
stdbuf -o0 ./program -a asdf
So that your buffered pipeline becomes:
stdbuf -o0 ./program -a asdf | script.sh
Related videos on Youtube
Florian Bach
PGP key: F19A 5DCB 1186 79C2 0ABB 19F4 E431 5998 4795 401E
Updated on September 18, 2022Comments
-
Florian Bach over 1 year
I have a (proprietary) program which I start with
./program -a asdf
in the Terminal. When I do that, I can see all the output at the right time.However, when I want to use the programs' output in a script of mine and run
./program -a asdf | script.sh
, with "script.sh" just containingread line
andecho $line
in a loop, the output of the program is "weird". When the program prints the first block of lines, the script doesn't print anything. When the program (a few minutes later) prints the 2nd block of lines, my script will print the first block.Why?
Is there a way for my own script to "act like a terminal" to get the output as soon as it would show up in the terminal?