http://qs1969.pair.com?node_id=37063

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: (programs and processes)

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

Originally posted as a Categorized Question.

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

Replies are listed 'Best First'.
Re: How do I start two programs without waiting for first one to be finished ?
by tye (Sage) on Oct 17, 2000 at 10:12 UTC
    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
Re: How do I start two programs without waiting for first one to be finished ?
by Anonymous Monk on Feb 10, 2001 at 00:59 UTC
    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";
Re: How do I start two programs without waiting for first one to be finished ?
by walto (Pilgrim) on Mar 16, 2008 at 07:02 UTC
    Linux:  system "first &";
    Windows:  system "start /b first";
    Both start first in background.
Re: How do I start two programs without waiting for first one to be finished ?
by runrig (Abbot) on Oct 17, 2000 at 04:23 UTC
    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: $!"; }