Solved

How to make a perl script run from another perl script

Posted on 2001-06-06
6
250 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 25 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

705 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