Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!cs.utexas.edu!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: pager pipes Message-ID: <1991Feb17.230545.16898@convex.com> Date: 17 Feb 91 23:05:45 GMT References: <1991Feb16.210445.7760@convex.com> <1991Feb17.024739.17286@iwarp.intel.com> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 46 Nntp-Posting-Host: pixel.convex.com From the keyboard of emv@ox.com (Ed Vielmetti): :Not exactly a followup to the above, but here goes. : :I have a pager set up for some particular output, like so : open(PAGER,$pager) || warn "meaningful warning"; : print PAGER (join("\n",@result),\n); : close(PAGER); : :The result can be kind of long-winded, so I'd like to let people :interrupt out of the pager and still be returned gracefully to the :main loop of my script. As it stands now, if $pager = "|cat" and you :control-C the output, you lose. : :Is it a matter of eval'ing something, or some kind of signal handler :to set up, or something else I'm missing. I wouldn't think that a ^C :sent to cat would leak back up to perl. Yes, you do indeed need to set up a signal handler. You probably want one for INT, maybe QUIT, and probably for PIPE as well. The PIPE is in case your $pager should bail out early or be absent. Unlike most applications of kill(2), a ^C will cause the the signal to be delivered to the entire process group, not just to the "active" process. This means that both the pager and perl will see it. I think that people who expect otherwise have been lulled into this belief by the behavior of system(3), which will ignore keyboard interrupts and quits. You don't normally need an eval for this kind of thing, nor would it really help you without the signal handler. However, one thing I have done along those lines is something like this: sub PLUMBER { die "caught SIG$_[0] -- plumber bailing out"; } $SIG{'PIPE'} = $SIG{'INT'} = $SIG{'QUIT'} = 'PLUMBER'; eval 'do something()'; die $@ if $@ && $@ !~ /bailing out/; This way I can in effect longjmp all the way back up to the call to something(), without having to muck about with getting all the intervening routines to return gracefully. Used in this way, you can think of die as raising an exception its caller can catch if they wish. --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "All things are possible, but not all expedient." (in life, UNIX, and perl)