Path: utzoo!attcan!uunet!decwrl!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.perl Subject: Re: Need $? for open() Keywords: new feature request Message-ID: <1990Mar27.163646.16898@iwarp.intel.com> Date: 27 Mar 90 16:36:46 GMT References: <23449@pasteur.Berkeley.EDU> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 39 In-Reply-To: grady@scam.Berkeley.EDU (Steven Grady) In article <23449@pasteur.Berkeley.EDU>, grady@scam (Steven Grady) writes: | The problem is that I don't find out if there's an error. What | would be really useful is for the "$?" variable (or something | like it) to be set to the status of the program when it exits. | Currently, $? is only set by backquoted programs, wait(), and | system(). Is there any possibility of adding generic open'ed | commands to this list, or at least some mechanism to provide | similar functionality? Already done. 'close' does it. Quoting from the manpage: Closing a pipe explicitly also puts the status value of the command into $?. For example, open(TRUE,"true|") || die "Cannot open true... sad but true! ($!)"; print grep(s/^/true: /, ); # show all the output (if any) close(TRUE) || die "Cannot close true... very weird ($!)"; print "true exited with $?\n"; open(FALSE,"false|") || die "Cannot open false... sad but false! ($!)"; print grep(s/^/false: /, ); # show all the output (if any) close(FALSE) || die "Cannot close false... very weird ($!)"; print "false exited with $?\n"; generates: true exited with 0 false exited with 256 Hope this helps... $|=1;$_=<<'-- ';s#..#printf"%c",(fork?wait&&$?/256:exit hex($&))#eg; 4a75737420616e6f74686572205065726c206861636b65722c -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/