in reply to execute command as well as prompt user
Here's one way (BTW. Using backticks and ignoring the output doesn't make a lot of sense):
use threads; use threads::shared; my % commands = ( CMD1 => process 1, CMD2 => process 2, CMD3 => process 3, ); foreach my $cmd(keys %commands) { my $done :shared = 0; async { `$commands{$cmd}`; if($?) { print ¨ Error: $commands{$cmd}\n¨; } $done = 1; }->detach; until( $done ) { for( 1 .. 60 ) { sleep 1; last if $done; } print ¨Still executing: $command{$cmd}\n¨ } }
|
|---|