Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How do I start two programs without waiting for first one to be finished ?

( #37063=categorized question: print w/ replies, xml ) Need Help??
Contributed by Anonymous Monk on Oct 17, 2000 at 04:11 UTC
Q&A  > programs and processes


Answer: How do I start two programs without waiting for first one to be finished ?
contributed by tye

system( 1, "first" ); # Won't wait. system( "second" ); # Will wait.

This is could be very portable though it also still appears to be mostly undocumented. ):

Update: I posted this long ago and later learned that system(1,...) was never allowed to work except on Windows (and OS/2, for which it was originally written). Any documentation on it appears to be relegated to perlport.

     - tye
Answer: How do I start two programs without waiting for first one to be finished ?
contributed by Zombie robyn

On Windows, I use this to launch one program and not wait, and then another with waiting.

use Win32::Process; my $path = "C:\\mydirectory\\myprogram.exe"; Win32::Process::Create( $Process, $path, "myprogram", 0, NORMAL_PRIORITY_CLASS, "." ) or die "Can't Create - $!"; chdir "c:\\Program Files\\CoolRuler"; system "coolruler.exe";
Answer: How do I start two programs without waiting for first one to be finished ?
contributed by walto

Linux:  system "first &";
Windows:  system "start /b first";
Both start first in background.

Answer: How do I start two programs without waiting for first one to be finished ?
contributed by runrig

Fork them and run in the background:

system "( sleep 10; ls -l ) &";
Or use fork() explicitly:
if ( $pid = fork ) { # this is the parent } elsif ( defined $pid ) { # this is the child system "myprogram"; } else { die "can't fork: $!"; }

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2014-09-15 04:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (145 votes), past polls