Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Intercepting the Mail output with a Perl program Message-ID: <1991May8.172447.28951@jpl-devvax.jpl.nasa.gov> Date: 8 May 91 17:24:47 GMT References: <6819@s3.ireq.hydro.qc.ca> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 36 In article <6819@s3.ireq.hydro.qc.ca> regie@ireq-robot.hydro.qc.ca (Regis Houde) writes: : : I wrote a program that intercepts the output of the standard : /usr/ucb/Mail program in order to interpret and replace a set of : characters. I'd like the program to behave exactly like the original : one so a program calling it (as mailtool) won't make any difference. : : Here is my program : : : #!/usr/bin/perl : # Name : Mail : # Usage : Mail : : # Make the stdio unbuffered : select((select(stdout), $| = 1)[0]); : select((select(stdin), $| = 1)[0]); : : open(IN,"/usr/ucb/mail @ARGV |"); : : while() : { : # Some simple code here : print ; : } : : It does pretty well except for the prompt that doesn't come at the : right time and this seems to bug mailtool when a user press the delete : button. I don't know if it's the whole story, but does line-oriented input, so any prompt not ending in newline is going to languish in the STDIN buffer until a newline comes along. Setting $| on STDIN has no effect. Replace the with sysread(STDIN,$_,1024) or read(STDIN,$_,1) and it should be closer to the truth. Larry