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

Hi all, I am sure this is easy?? I need to execute a load of programs over the weekend (say). How can i go about this, i have tried using a system command but all are exectuted at once with out waiting for the previous command to finish?
system "perl ....."; system "/Programs///exe something"; system "perl .....";
Thanks,

Replies are listed 'Best First'.
Re: executing a list of programs
by ccn (Vicar) on Jul 30, 2004 at 13:20 UTC

    On windows you can use start command:

    for ('perl script.pl', 'program.exe') { system("start $_") == 0 or warn "$_: $!"; }

    Also see fork, perlthrtut and threads to know how to run parallel processes and threads

Re: executing a list of programs
by roju (Friar) on Jul 30, 2004 at 14:31 UTC
    You could always cheat and let the shell do it for you: system "$command[0] ; $command[1] ; $command[2]";
Re: executing a list of programs
by friedo (Prior) on Jul 30, 2004 at 13:19 UTC
    system performs a fork first, which is why a new process is spawned for every program you run. If you want to run them sequentially, use exec.

    You may also want to use some sort of scheduling mechanism, such as Unix cron or a cool Perl version like Schedule::Cron.

      fork is done first, and the parent process waits for the child process to complete.

      So, using system you can not run processes simultaneously. But if you use exec, you can not run a list of processes, as OP wants, because the exec never returns.

Re: executing a list of programs
by Anonymous Monk on Jul 30, 2004 at 16:24 UTC
    if your code is working then why don't you add sleep(n); to your each file just to make your life easy. where n is the exact time you want it to run.