Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Questions about exec and scripts called from cron Message-ID: <9733@jpl-devvax.JPL.NASA.GOV> Date: 28 Sep 90 21:38:55 GMT References: <1180002@hpcc01.HP.COM> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 39 In article <1180002@hpcc01.HP.COM> okamoto@hpcc01.HP.COM (Jeff Okamoto) writes: : Two more puzzling questions for patchlevel 18: : : 1. Why does this construct not do what I think it should? : : exec "/non-existent-file" || die "Can't exec: $!\n"; Because exec is a list operator, and thus has a lower precedence than ||. Say this: exec("/non-existent-file") || die "Can't exec: $!\n"; or exec "/non-existent-file"; die "Can't exec: $!\n"; : 2. Why does this construct not work when this script is called : from cron? : : #!/usr/local/bin/perl : eval "exec /usr/local/bin/perl -S $0 $*" : if $running_under_some_shell; I don't have enough to go on here, but bear in mind a coupla three things. First, cron runs without much of a PATH, and the -S switch above uses PATH to try to locate the script. Second, cron could conceivably be feeding the text above to /bin/sh through stdin, in which case $0 isn't going to be meaningful, and you'd probably try to execute the first argument of $*. Third, if the arguments you're passing contain any whitespace, you should instead use eval 'exec /usr/local/bin/perl -S $0 "${1+$@}"' if $running_under_some_shell; Hope that helps. You might just invoke perl directly from cron instead of relying on the eval-exec hack. Larry