Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: running multiple system commands in parallel

by BrowserUk (Patriarch)
on Aug 28, 2009 at 20:12 UTC ( [id://792007]=note: print w/replies, xml ) Need Help??


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.

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://792007]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2025-04-22 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.