Tuesday, March 1, 2011

Catch 22 using exec in perl forks

I just found a nasty little problem using perl exec.

#!/usr/bin/env perl

my @a = ("sh -c 'asdfsadf ls'", "echo hi", "echo a");

foreach my $b (@a) 
{
    if(fork()==0) 
    {
        exec($b); 
        die "Gahh: $b";
    }
}

print "done\n";

Note what happens when in the case of sub shells and exec:
perl -e "exec('sh -c asdflkj'); die 'gahh';"

No comments:

Post a Comment