Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!fub!einoed!uwbln!jde From: jde@uwbln.uniware.de (Jutta Degener) Newsgroups: comp.unix.questions Subject: Re: redirected output is buffered, how do you flush it? Message-ID: <1991Feb10.081651.24841@uwbln.uniware.de> Date: 10 Feb 91 08:16:51 GMT References: <1991Feb05.000629.7401@convex.com> <1892:Feb521:11:4591@kramden.acf.nyu.edu> Organization: UniWare Computer GmbH, Berlin Lines: 39 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 jutta@tub.cs.tu-berlin.de