Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

simultanious system calls on windows

by mmittiga17 (Scribe)
on Sep 11, 2012 at 19:10 UTC ( [id://993035]=perlquestion: print w/replies, xml ) Need Help??

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

Trying to find a way to have a perl script run 4 other perl scripts on windows and then once all are done, kick off a 5th script. I have checked out a bunch of things but none seem straight forward. Suggestions welcome. The scripts are going to run on a windows box. scripts 1-4 need to finish first before starting script 5

Replies are listed 'Best First'.
Re: simultanious system calls on windows
by Anonymous Monk on Sep 11, 2012 at 19:17 UTC

    I have checked out a bunch of things but none seem straight forward

    What bunch?

    use Proc::Background

      #!/usr/bin/perl -- use strict; use warnings; use Proc::Background; my @commands = ( [ 'echo', 'arg','arg', ] , [ 'perl', '-le',' print 1; sleep 1; warn 2; sleep 1; die 3;' ], ); my @procs = map { Proc::Background->new(@$_); } @commands; $_->wait for @procs; system 'echo', 'nowTheyAreAllDead.pl', '--pidsAndExitStatus', map { $_ +->pid, $_->wait } @procs; __END__ arg arg 1 2 at -e line 1. 3 at -e line 1. nowTheyAreAllDead.pl --pidsAndExitStatus 2956 0 2120 65280
Re: simultanious system calls on windows
by Rudolf (Pilgrim) on Sep 11, 2012 at 19:29 UTC

    Since you want 4 processes to finish before you begin the 5th, you could run 4 child processes and tell the parent process to wait ( halt execution ) until all those return. The main problem I could see running into which I have in the past is saving the data from those processes in variables you associate with the parent process. But this is one way to do it, though they won't really be seperate "scripts" in the file-sense.

Re: simultanious system calls on windows
by bulk88 (Priest) on Sep 11, 2012 at 21:55 UTC
    Dont use perl, use the Windows Shell.
    for(0..4){ print "starting $_\n"; system("start", "perl.exe", '-e', 'print qq!hello world\n!;sleep 1;' +); print "end of starting $_\n"; }
    You will notice the 1st console box will say "end of starting 4" before all 5 new consoles disappear. No pipes, no FDs and no pids to worry about. But you won't know when the childs are done.

      Dont use perl, use the Windows Shell. ..... But you won't know when the childs are done.

      I would stick with perl, you can know when childs are done.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-03-28 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found