my $pid=spawn("/usr/bin/ps","test1.out"); waitpid($pid,0); print "test1.out not created" if not -e "test1.out"; # # More code # sub spawn { my($cmd,$redirect)=@_; my $pid=fork(); return $pid if $pid > 0; if ( $pid == 0 ) { # Child process exec sprintf("%s > %s",$cmd,$redirect) or die "Could not exec $cmd:$!"; } else { # uh-oh... could not fork die "Could not fork $cmd : $!"; } }