?
Solved

Run 2 perl scripts simultaneously within a perl script

Posted on 2005-02-28
3
Medium Priority
?
382 Views
Last Modified: 2008-03-17
I am write a perl script which will run 2 other perl scripts.  In these 2 perl scripts, they do some processing, but I need them to run simultaneously without having to wait for the 1st one to finish.

How do I go about doing this?
0
Comment
Question by:jewee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 1000 total points
ID: 13424857
On a Unix system, you can do:

#!/usr/bin/perl
system "prog1 &" and die "Can not run prog1 $!\n";
system "prog2 &" and die "Can not run prog2 $!\n";
print "Finished\n";

However, if you want more portability and flexibility, you should use 'fork'.
0
 
LVL 16

Accepted Solution

by:
manav_mathur earned 1000 total points
ID: 13427465
#!/usr/bin/perl
system "prog1&prog2&" and die "Failed $!\n";
print "Finished\n";

or
#!/usr/bin/perl
die("$! : Cant fork") unless (defined($pid = fork)) ;
if($pid) {
##parent process
system("prog1") and die("$! : prog1 failed") ;
}else{
##child process
system("prog2") and die("$! : prog2 failed");
}


0
 
LVL 16

Expert Comment

by:manav_mathur
ID: 13448283
??

Manav
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question