>...my $ret = undef; >...my $pid = undef; >...if( $pid = fork()){ >...>...#here i store the pid in some array for other process >...} >...elsif( defined $pid){ >...>...$ret = system($cmd); >...>...open(my $f,">","/tmp/$$") or die "couldn't write file"; >...>...print $f $ret; >...>...close($f); >...>...die;#not sure if this is the proper way to kill the child, not my main worry in this question >...} >...else{ >...>...print "\n couldnīt fork\n"; >...} >...waitpid($pid,0); >...if( open(my $F, "/tmp/$pid")){ >...>...while( my $line = <$F>){ >...>...>...$ret .= $line; >...>...} >...>...close($F); >...>...system("rm /tmp/$pid"); >...} >...else{ >...>...$ret = -1; >...}