home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7503 < prev    next >
Encoding:
Text File  |  1992-12-18  |  1.1 KB  |  35 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!sybus.sybus.com!myrddin!tct!chip
  3. From: chip@tct.com (Chip Salzenberg)
  4. Subject: Re: system() vs exec()
  5. Message-ID: <2B30FF95.7BC3@tct.com>
  6. Date: Thu, 17 Dec 1992 22:30:43 GMT
  7. References: <mcook.724446650@fendahl.dev.cdx.mot.com> <1992Dec16.160845.17636@news.eng.convex.com> <2B30B274.616E@tct.com>
  8. Organization: TC Telemanagement, Clearwater, FL
  9. Lines: 24
  10.  
  11. Aargh!  I myself posted:
  12.  
  13. >    sub system {
  14. >        local($pid) = fork;
  15. >        return undef unless defined($pid);
  16. >        $pid ? wait : exec @_;
  17. >    }
  18.  
  19. I stupidly failed to account for exec failure!
  20.  
  21. Try this instead:
  22.  
  23.    sub system {
  24.        local($pid) = fork;
  25.        unless (defined($pid)) { return undef; }
  26.        unless ($pid) { exec @_; die "can't exec $_[0]: $!\n"; }
  27.        waitpid($pid, 0);
  28.    }
  29.  
  30. -- 
  31. Chip Salzenberg at Teltronics/TCT  <chip@tct.com>, <73717.366@compuserve.com>
  32.   "you make me want to break the laws of time and space / you make me
  33.    want to eat pork / you make me want to staple bagles to my face /
  34.    and remove them with a pitchfork" -- Weird Al Yankovic, "You Make Me"
  35.