🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1851

Re: Clearing the input buffer before a read.

#1851
From: Paul Chamberlain
Date: Mon, 26 Nov 1990 16:36
17 lines
1226 bytes
In article <1990Nov26.001425.15563@massey.ac.nz> K.Spagnolo@massey.ac.nz (Ken Spagnolo) writes:
>I want to
>be able to flush the input buffer just before the read ...

This is pretty nasty but it might do what you want:

	old_modes=`stty -g`		# save old modes
	stty -icanon min '^@' time '^@'	# read whats already there
	read junk			# read all thats waiting
	stty $old_modes			# restore old modes

You may want to make this bullet-proof about interrupts though.

I tried this on AIX Version 2 (RT).

Paul Chamberlain | I do NOT represent IBM.     tif@doorstop, sc30661 at ausvm6
512/838-7008     | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif
Technical Details
Message-ID: <4328@awdprime.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!romp!auschs!awdprime!doorstop.austin.ibm.com!tif
References: <1990Nov26.001425.15563@massey.ac.nz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!cs.utexas.edu!romp!auschs!awdprime!doorstop.austin.ibm.com!tif
From: tif@doorstop.austin.ibm.com (Paul Chamberlain)
Newsgroups: comp.unix.shell
Subject: Re: Clearing the input buffer before a read.
Message-ID: <4328@awdprime.UUCP>
Date: 26 Nov 90 16:36:04 GMT
References: <1990Nov26.001425.15563@massey.ac.nz>
Sender: news@awdprime.UUCP
Reply-To: tif@doorstop.austin.ibm.com (Paul Chamberlain)
Organization: IBM AWD, Austin, TX
Lines: 17