Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to make a perl script run from another perl script

Posted on 2001-06-06
6
Medium Priority
?
260 Views
Last Modified: 2010-03-05
Is it possible to get a perl script to run another perl script when it has finished running through its own loop?
Basically I have two scripts that work independently but when I patch the two together they stop working.
0
Comment
Question by:j1mlondon
[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
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
Sapa earned 100 total points
ID: 6159013
There are several ways to implement it:

1. Run another script in the same copy of Perl-interpreter:

--------- script1.pl ------------
....
....
do "script2.pl";
------------- EOF ----------------

but all global variables and opened file descriptors will be inherited by script2.pl. It may cause the side effects.
If you cannot change the body of script1.pl use this command line: perl -e "do 'script1.pl'; do 'script2.pl';"

2. Launch the new interpreter and wait when it finished:

--------- script1.pl ------------
....
....
system "/usr/bin/perl script2.pl";
------------- EOF ----------------
or

perl -e "do 'script1.pl'; system '/usr/bin/perl script2.pl';"

3. Substitute the current Perl interpreter by the new one:

--------- script1.pl ------------
....
....
exec "/usr/bin/perl script2.pl";
------------- EOF ----------------

or

perl -e "do 'script1.pl'; exec '/usr/bin/perl script2.pl';"

On most of OS's you can omit the interpreter path from system or exec if execution bit is set and #!<path_to_perl> line exists (on Unix) or suffix .pl is registered as interpreted by Perl (Windows).

- Sapa

P.S. "Basically I have two scripts that work independently". If they are really independent, may be better to launch it simultaneously?

0
 

Author Comment

by:j1mlondon
ID: 6159032
The scripts are not independent totally.
I actually wish to carry variables over from one script ie script1 into script2 exactly as they are.
Will this work using your first part of the answer?
0
 

Author Comment

by:j1mlondon
ID: 6159044
The scripts are not independent totally.
I actually wish to carry variables over from one script ie script1 into script2 exactly as they are.
Will this work using your first part of the answer?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:Sapa
ID: 6159716
yes. the first method only is acceptable in this case.
0
 

Author Comment

by:j1mlondon
ID: 6159752
Thanks. It worked , but I am getting error messages, even though it works how I want it to.
The error is..
Statement unlikely to be reached at *.pl line 18
       (Maybe you meant system() when you said exec()?
Can't exec "
Starting ":No such file or directory at *.pl  line 17, <FP> chunk 3.


What is the bit about chunk3 ????
0
 
LVL 5

Expert Comment

by:Sapa
ID: 6160093
It means you have exec(...) function and the part of code after it. But function exec(...) does never return, except error is occured (as in your case).

So "Statement unlikely to be reached at *.pl line 18" is warning about this code cannot be executed because exec(...) will substitute current program by the new one. And may be you want to use system(...) which execute external program and continue execution after new program will be finished.

Can't exec "
Starting ":No such file or directory at *.pl  line 17, <FP> chunk 3

function exec(...) failed because there is no such program "\nStarting" (may be you need to remove \n ?)
"chunk 3" usually means an iterration number while reading from file FP.

- Sapa
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

604 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