Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: Pipe question Keywords: pipe filter Message-ID: <1991Mar13.094313.8912@athena.mit.edu> Date: 13 Mar 91 09:43:13 GMT References: <9669@exodus.Eng.Sun.COM> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 37 In article <9669@exodus.Eng.Sun.COM>, pew@grieg.Eng.Sun.COM (John Pew) writes: |> When the parent tries to read |> from the filter it never returns from the read. Any suggestions would |> be appreciated. Put "(void) close(fd1)" directly after your write() to the child in the parent. The filter never sees EOF, so (if it's using stdio) it never gets any input to process and send back to you, because the text you have sent it isn't large enough to fill stdio's input buffer, nor does it have a carriage return at the end of it to force it through (if the filter were working on a line-by-line basis). If you only use the filter once (i.e. you always open the filter, send some amount of data to it, read the result and then close the pipe to the filter), you can solve your problem simply by closing the pipe to the filter before trying to read data. If you need the filter to stay around, then you'll have to figure out some way to get it to do line-buffering, possibly by running it on a pty instead of on a pipe. Or you could use execlp("pty", "tr", "tr", "a-z", "A-Z", 0); if you don't want to bother to learn how to use pty's in C, and if you've got pty's installed on your system. (Note to all of you who are reading this in disgust -- I had to say it, or Dan would have! :-) And, of course, if it's doing line-buffering, then you'll have to make sure that your input always ends in a newline. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710