This sounds like a good use case for Forks::Super::bg_qx .
use Forks::Super 'bg_qx'; $output = bg_qx $bashcommand; $output1 = bg_qx $bashcommand1; $output2 = bg_qx $bashcommand2; $output3 = bg_qx $bashcommand3;
will run these four commands in the background. Variables used for return values ( $output , $output1 , etc.) are overloaded objects. Your program will extract the output from these commands (waiting for the completion of the commands, if necessary) the next time these variables are specified in the program.
... more stuff happens ... # if $bashcommand is done, this next line will execute right away # otherwise, it will wait until $bashcommand finishes ... print "Output of first command was ", $output; &do_something_with_command_output( $output1 ); @output2 = split /\n/, $output2; ...
Update 2012-03-01: v0.60 from Forks :: Super has several new constructs that allow you to retrieve results in a list context:
if ($condition) { tie @output, 'Forks::Super::bg_qx', $bashcommand; tie @output1, 'Forks::Super::bg_qx', $bashcommand1; tie @output2, 'Forks::Super::bg_qx', $bashcommand2; tie @output3, 'Forks::Super::bg_qx', $bashcommand3; } ...
source share