Re: Flushing all Buffers Before Exiting
On Thu, Mar 21, 2019 at 06:01:26PM -0000, Curt wrote:
> I'm reading a pty app won't buffer (script, screen, etc.).
Well, it's a convention, adopted by the C library functions in stdio.
stdio(3) says:
At program startup, three text streams are predefined and need not be
opened explicitly: standard input (for reading conventional input),
standard output (for writing conventional output), and standard error
(for writing diagnostic output). These streams are abbreviated
stdin,stdout and stderr. When opened, the standard error stream is not
fully buffered; the standard input and output streams are fully
buffered if and only if the streams do not refer to an interactive
device.
Output streams that refer to terminal devices are always line buffered
by default; pending output to such streams is written automatically
whenever an input stream that refers to a terminal device is read. In
cases where a large amount of computation is done after printing part
of a line on an output terminal, it is necessary to fflush(3) the stan‐
dard output before going off and computing so that the output will
appear.
> And then there's a program called 'unbuffer'?
It's a hack, built around Expect. It basically tries to fool the
application into thinking that standard output is a terminal, so the
application will operate in line-buffering mode.
I've been told that it works quite often, but you can't ever guarantee
success with it.
Reply to: