redirected output is buffered, how do you flush it?

Jutta Degener jde at uwbln.uniware.de
Sun Feb 10 19:16:51 AEST 1991


Robert L. Howard asks:
:I have a script that after several pipe stops outputs a line
:of information. [...]
:
:The problem comes in when I run:
:
:% script > some_file
:
:and then kill it some number of minutes later.  The total output
:of the script is still in some buffer somewhere and doesn't make
:it to the file.  Is there some command I can put in the 'trap' to
:force it to flush the buffers?  Or is there a recommended way to
:kill the job (other than ^C) that will force the buffers to flush?

Tom Christiansen answers:
> Here's a fairly direct translation of your program into perl, 

To which Dan Bernstein replies:
> Here's a very easy general solution: Run % pty script > some_file

When you hit '^C', both the shell and its subprocess, awk, are killed.
Unfortunately, as Tom already mentioned, awk doesn't flush its buffers.

trap "" 1 2 3 .. etc will ignore signals for both a shell and its 
subprocesses. (On the systems I checked.)  Try:

trap "exit 0" 1 2 3 15
{ echo piling lies
  while :
  do
	sleep 1
	echo upon lies
  done } | (
	trap "" 1 2 3 15;
	awk '/lies/{ l++ } END { printf("%d lies successfully piled.\n", l ) }'
)

--
#include <std/disclaimer.h>      		    jutta at tub.cs.tu-berlin.de



More information about the Comp.unix.questions mailing list