Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!sco!md From: md@sco.COM (Michael Davidson) Newsgroups: comp.unix.programmer Subject: Re: popen ... Message-ID: <12740@scolex.sco.COM> Date: 24 Jun 91 18:22:46 GMT References: <1991Jun20.004507.17814@menudo.uh.edu> Sender: news@sco.COM Lines: 22 svec5@menudo.uh.edu (T.C. Zhao) writes: [ ... ] >everything seems working ok except when more quits prematurely(q), >the program exits. I do not think this is the way popen supposed to >work, but I would like to make sure.( smell bugs in the program >somewhere.) The other question is how to catch the premature exit >of more in the program (broken pipe?), checking fprintf return >does not seem do the trick. You almost have the answer - the problem is the broken pipe caused when "more" exits. The solution is to alter the default signal handling behaviour for SIGPIPE. You can set up a signal handler for SIGPIPE - all it needs to do is to set a global flag to indicate that a SIGPIPE was caught, and then return. Alternatively you should simply be able to set the behaviour for SIGPIPE to SIG_IGN and then you should get an error back from your attmpts to write to the pipe (but beware of the layer of buffering that stdio may be adding to your writes, and also beware of the fact that the fwrite() and fprintf() routines don't guarantee anything about the contents of errno ...)