if( my $pid = fork ) {
print "I am the parent pid ($$), and I'm going to wait for $pid to
+ exit.\n";
my $kid;
do {
$kid = waitpid $pid, 0;
} while $kid > 0;
exit 0;
} else {
exec(qw(ls -al /tmp)); die "hrm, exec() failed: $!";
}
Using a '&' in the system() call causes perl to fork a shell and asks the shell to fork a kid. Then the shell returns and perl completely looses track of the kids.
UPDATE: Also, I just noticed that you probably need some kind of redirection:
# exec(qw(ls -al /tmp)); die ... blah
open my $out, ">", "filename" or die $!;
open my $in, "-|", qw(ls -al /tmp) or die $!;
print $out $_ while <$in>;
close $out;
close $in;
|