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

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!cs.utexas.edu!hermes.chpc.utexas.edu!news.utdallas.edu!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: system() vs exec()
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Dec16.160845.17636@news.eng.convex.com>
  8. Date: Wed, 16 Dec 1992 16:08:45 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <mcook.724446650@fendahl.dev.cdx.mot.com>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 28
  17.  
  18. From the keyboard of mcook@fendahl.dev.cdx.mot.com (Michael Cook):
  19. :This means that a Perl script that use system() can be difficult to interrupt.
  20. :  foreach (@files)
  21. :  {
  22. :    system("cp $_ $dest/$_");
  23. :    $exit = $? if $?;
  24. :  }
  25. :  exit($exit);
  26. :
  27. :If you try to ^C this script, it will simply start a new iteration of the
  28. :foreach loop (most likely).
  29. :
  30. :If you write the script using fork, exec and waitpid, when you hit ^C it does
  31. :what you'd expect: it dies.
  32. :
  33. :At best, this is a bug in the manpage.  At worst, it is a bug in perl.
  34.  
  35. Well, it's really just behaving like system(3) out of the C library.
  36. You can always check ($signo = $? & 127) on many systems, or write
  37.  
  38.     sub system { fork ? wait : exec @_ }
  39.  
  40. --tom
  41. -- 
  42.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  43. There are probably better ways to do that, but it would make the parser
  44. more complex.  I do, occasionally, struggle feebly against complexity...  :-)
  45.             --Larry Wall in <7886@jpl-devvax.JPL.NASA.GOV>
  46.