Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm trying to spawn off a shell process to download an image. It's in a loop as there are a few hundred of these (hence the need to do it in parrallel and not use LWP), but I've reduced to the code to the actual issue.

The problem is that the subprocess never returns. Can anyone spot the glaring flaw in my code?

print "here is ok\"; &spawnwebget("wget somesite.com/webcam.jpg;".'if [ $? -ne 0 ];'." then + cp ./images/broken.jpg webcam.jpg;fi"); print "never gets here\n"; sub spawnwebget { my ($url)=@_; #avoid zombies my $pid = fork; next if $pid; warn($!), next if not defined $pid; exec ($url); #never reaches here return; }

Replies are listed 'Best First'.
Re: spawning exec fails to return
by jkeenan1 (Deacon) on Oct 31, 2013 at 01:25 UTC
    perldoc -f exec

    Jim Keenan
      when I change exec to system, I have the same problem.
        Does the system call actually exit when it's done? If not, it won't come back.