Hi Perl Monks, i would like to get the exact same behaviour that i get with $ret = system( "some command"); but in addition i want to get the pid of that command, i been reading about the differences between exec,system and backticks, as i understand none of these is usefull for what i want to do. what worked for me was this:
>...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; >...}
i know this is suuper awfull, so mi question is: how i do this properly? p.s: sorry my english, and be good, this is my first question here.
p.s 2: i think the get_pidof function wont do because there will be several identical commands running at the same time.
In reply to get same return that system gives and get pid by Raiden690
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |