Help - Search - Member List - Calendar
Full Version: call a perl script within another perl script
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Nishi Prafull
Hi:
I would like to call a perl script(B.pl) within another perl script(A.pl).
Should I use the following approach or something else?

A.pl
-----
my $cmd = "perl B.pl"
system($cmd);

Please let me know.
Thanks.

Tim Johnson
I guess it partly depends on what you are trying to accomplish. Why are
you calling a second script?




-----Original Message-----
From: Nishi Prafull [mailto:[Email Removed]]
Sent: Thursday, March 03, 2005 3:47 PM
To: [Email Removed]
Subject: call a perl script within another perl script

Hi:
I would like to call a perl script(B.pl) within another perl
script(A.pl).
Should I use the following approach or something else?

Nishi Prafull
Hi:
Apparently I noticed that when I put both the commands I need to run
in one script using the system call, the second command does not get
executed ( I cannot figure out the cause).
Each of the commands are making out calls to software installed on the
machine to perform specific tasks.

Do I have to do anything else in this regard?

Thanks.

On Thu, 3 Mar 2005 15:50:16 -0800, Tim Johnson <[Email Removed]> wrote:
QUOTE

I guess it partly depends on what you are trying to accomplish.  Why are
you calling a second script?


-----Original Message-----
From: Nishi Prafull [mailto:[Email Removed]]
Sent: Thursday, March 03, 2005 3:47 PM
To: [Email Removed]
Subject: call a perl script within another perl script

Hi:
I would like to call a perl script(B.pl) within another perl
script(A.pl).
Should I use the following approach or something else?



Nishi Prafull wrote:
QUOTE
Hi:
Apparently I noticed that when I put both the commands I need to run
in one script using the system call, the second command does not get
executed ( I cannot figure out the cause).
They would have to be two separate calls.  I used to start 10 to 15 processes at one time using a Perl script to get my setup the way I wanted it.  Then I knew exactly where they were and the order they were in.


So you only need to do;

my $MyStatus1 = system('script1.pl'); # make sure you qualify the script as much as necessary and not rely on # paths.
# should check that status was a success which i believe is backwards from what Perl defines as success(0: good, <> # 0:error)

my $MyStatus2 = system('script2.pl'); # second one to execute.

Wags ;)
QUOTE
Each of the commands are making out calls to software installed on the
machine to perform specific tasks.

Do I have to do anything else in this regard?

Thanks.

On Thu, 3 Mar 2005 15:50:16 -0800, Tim Johnson <[Email Removed]
wrote:

I guess it partly depends on what you are trying to accomplish.  Why
are you calling a second script?


-----Original Message-----
From: Nishi Prafull [mailto:[Email Removed]]
Sent: Thursday, March 03, 2005 3:47 PM
To: [Email Removed]
Subject: call a perl script within another perl script

Hi:
I would like to call a perl script(B.pl) within another perl
script(A.pl). Should I use the following approach or something else?



*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************

Nishi Prafull
Apparently, the first command spawns a new shell when it is executed
and the control is never returned back and hence i cannot get the
second command to get executed.
So I am trying to evaluate the -exec option.

Thanks.


On Thu, 3 Mar 2005 16:14:30 -0800, Wagner, David --- Senior Programmer
Analyst --- WGO <[Email Removed]> wrote:
QUOTE
Nishi Prafull wrote:
Hi:
Apparently I noticed that when I put both the commands I need to run
in one script using the system call, the second command does not get
executed ( I cannot figure out the cause).
They would have to be two separate calls.  I used to start 10 to 15 processes at one time using a Perl script to get my setup the way I wanted it.  Then I knew exactly where they were and the order they were in.

So you only need to do;

my $MyStatus1 = system('script1.pl');  # make sure you qualify  the script as much as necessary and not rely on                                                                # paths.
# should check that status was a success which i believe is backwards from what Perl defines as success(0: good, <>    # 0:error)

my $MyStatus2 = system('script2.pl');  # second one to execute.

Wags ;)
Each of the commands are making out calls to software installed on the
machine to perform specific tasks.

Do I have to do anything else in this regard?

Thanks.

On Thu, 3 Mar 2005 15:50:16 -0800, Tim Johnson <[Email Removed]
wrote:

I guess it partly depends on what you are trying to accomplish.  Why
are you calling a second script?


-----Original Message-----
From: Nishi Prafull [mailto:[Email Removed]]
Sent: Thursday, March 03, 2005 3:47 PM
To: [Email Removed]
Subject: call a perl script within another perl script

Hi:
I would like to call a perl script(B.pl) within another perl
script(A.pl). Should I use the following approach or something else?

*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************



Rathna N
then what about thru (``) Backtic or open call ?

Syntax:
1. $x=`ps -ef`;
2. open(fh,"$cmd |");

Regards,
Rathna



On Thu, 3 Mar 2005 16:25:45 -0800, Nishi Prafull <[Email Removed]> wrote:
QUOTE
Apparently, the first command spawns a new shell when it is executed
and the control is never returned back and hence i cannot get the
second command to get executed.
So I am trying to evaluate the -exec option.

Thanks.

On Thu, 3 Mar 2005 16:14:30 -0800, Wagner, David --- Senior Programmer
Analyst --- WGO <[Email Removed]> wrote:
Nishi Prafull wrote:
Hi:
Apparently I noticed that when I put both the commands I need to run
in one script using the system call, the second command does not get
executed ( I cannot figure out the cause).
They would have to be two separate calls.  I used to start 10 to 15 processes at one time using a Perl script to get my setup the way I wanted it.  Then I knew exactly where they were and the order they were in.

So you only need to do;

my $MyStatus1 = system('script1.pl');  # make sure you qualify  the script as much as necessary and not rely on                                                                # paths.
# should check that status was a success which i believe is backwards from what Perl defines as success(0: good, <>    # 0:error)

my $MyStatus2 = system('script2.pl');  # second one to execute.

Wags ;)
Each of the commands are making out calls to software installed on the
machine to perform specific tasks.

Do I have to do anything else in this regard?

Thanks.

On Thu, 3 Mar 2005 15:50:16 -0800, Tim Johnson <[Email Removed]
wrote:

I guess it partly depends on what you are trying to accomplish.  Why
are you calling a second script?


-----Original Message-----
From: Nishi Prafull [mailto:[Email Removed]]
Sent: Thursday, March 03, 2005 3:47 PM
To: [Email Removed]
Subject: call a perl script within another perl script

Hi:
I would like to call a perl script(B.pl) within another perl
script(A.pl). Should I use the following approach or something else?

*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************



--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response




--
Regards,
Rathna.

Chris Devers
On Thu, 3 Mar 2005, Nishi Prafull wrote:

QUOTE
I would like to call a perl script(B.pl) within another perl script
(A.pl). Should I use the following approach or something else?

A.pl
-----
my $cmd = "perl B.pl"
system($cmd);

Please let me know.

Is there a reason that A.pl can't just say

require "B.pl";

?



--
Chris Devers


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.