Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Invoke multiple applications

by gpurusho (Acolyte)
on Oct 19, 2004 at 16:38 UTC ( [id://400585]=perlquestion: print w/replies, xml ) Need Help??

gpurusho has asked for the wisdom of the Perl Monks concerning the following question:

Need: Invoke multiple applications simultaneously from a perl script.

OS : Windows 2000

Desc: I need to start several appliactions ( *.exe files). I tried calling the exes one by one but the problem is that it waits for one process to get over before the other exe is invoked. How do i start several applications at the same time ( ie without waiting for hte otehr to get completed). This will save a lot of time for me as these process are independent of each other.

Thanks

Replies are listed 'Best First'.
Re: Invoke multiple applications
by BrowserUk (Patriarch) on Oct 19, 2004 at 17:01 UTC

    #! perl -slw use strict; use threads qw[ async ]; my @threads; push @threads, async{ system '\path\to\first.exe' }; push @threads, async{ system '\path\to\second.exe' }; $_->join for @threads;

    See the docs for threads, and the async() function for more details.

    There is also an (undocumented?) option to the system command (on Win32?) that detaches the command run and doesn't wait.

    system 1, '\path\to\your.exe';

    The caveat with this is that once started, your script no longer retains any control over the app and doesn't recieve notification of it finishing.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
Re: Invoke multiple applications
by ikegami (Patriarch) on Oct 19, 2004 at 16:58 UTC
    Look into fork+exec in perlfunc (and read perlipc while you're at it), IPC::Open2 (included with perl), IPC::Open3 (included with perl) and Win32::Process (included with ActivePerl). Everyone of these will do the trick. The last one is probably the easiest to use (and probably the most efficient), but it's not portable.
Re: Invoke multiple applications
by Juerd (Abbot) on Oct 19, 2004 at 20:37 UTC

    One of the many ways to do this in Windows is using START, a program that... starts programs.

    system start => $_ for @exethingies;
    (Note that start => $_ is just fancy syntax for 'start', $_.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Invoke multiple applications
by Nitrox (Chaplain) on Oct 21, 2004 at 01:11 UTC
    I recently needed to do something similar and found Proc::Background very helpful.

    -Nitrox

      Thanks a lot, to everyone who replied, for the Help. I was able to get it done based on your suggestions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-26 09:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found