Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Need $? for open() Keywords: new feature request Message-ID: <100906@convex.convex.com> Date: 28 Mar 90 13:40:40 GMT References: <23449@pasteur.Berkeley.EDU> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 55 In article <23449@pasteur.Berkeley.EDU> grady@postgres.berkeley.edu writes: >I have a perl program which starts another process and reads >the input, using open(). Specifially, the relevant part of the >code looks something like: > > open(RLOG, "rlog $files |") || die "rlog: $@"; > while () { > ... > } > >The problem is that I don't find out if there's an error. I addressed this in <5016@convex.convex.com> of very nearly two months ago. It's brief, so I'll include the original here. --tom Date: 31 Jan 90 05:54:28 GMT From: tchrist@convex.com (Tom Christiansen) Subject: Testing successful pipe opens Organization: Convex Computer Corp, Richardson, TX Message-ID: <5016@convex.convex.com> Newsgroups: comp.lang.perl It's known that opening pipes to non-existent programs doesn't usually trigger useful error diagnostics. In particular, while writing on a badly-opened output pipe will (eventually) trigger a SIGPIPE (which you can look for), reading from a badly-opened input pipe just gets you EOF. A possible work-around for the bad input pipe follows: $kid = open (PIPE, "bogus_command |"); # really should check $kid != 0 (kill 0, $kid) || die "bogus_command failed"; This works fine if bogus_command doesn't have shell metas in it, but if it does, the shell may well not have exited before the kill 0. You can introduce a delay, $kid = open (PIPE, "bogus_command : Editor too big!"