in reply to running multiple system commands in parallel

If you like simple, then where you would code:

#! perl -slw use strict; #... my $output1 = `somecommand`; my $output2 = `someothercommand`; #... print for $output1, $output2;

Do:

#! perl -slw use strict; use threads; #... my $t1 = async{ `perl -e"print, sleep 1 for 1 ..10"` }; my $t2 = async{ `perl -le"print, sleep 1 for 'a'..'z'"` }; #... my $output1 = $t1->join; my $output2 = $t2->join; print for $output1, $output2;

(Note:The second snippet is an actual working example!)

And er...that's it really. It requires a little more if you have lots of commands to run and reason to limit the level of concurrency. But not much.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP PCW It is as I've been saying!(Audio until 20090817)

Replies are listed 'Best First'.
Re^2: running multiple system commands in parallel
by incognito129 (Acolyte) on Aug 29, 2009 at 12:43 UTC
    This works great and so unbelievably simple!