How can I call one Perl script from another?

10 comments

If you would like to make a call to, or reference, a Perl script from within a different Perl script, you can accomplish this a system(), exec() or the backtick operator to the path for Perl. For example:

system("/usr/bin/perl /path/to/my_script.pl ");

Or store output to array:

@myarray = `/usr/bin/perl mysecondperlscript.pl`;

{ 10 comments… read them below or add one }

Mentifex August 23, 2005 at 5:42 am

So maybe an AI Perlmind — an artificial intelligence written in Perl — could rewrite its own code with improvements and enhancements, then call the new version of itself by the methods described in this weblog.

Reply

Sarat Chandra September 8, 2005 at 2:41 pm

How do i call a “.cmd” from a perl script

Reply

Administrator September 8, 2005 at 5:51 pm

If i’m not mistaken you mean batch file under NT/XP use system command
system(“c:\path\to\my.cmd”);

Reply

Seetaram Srungaram December 29, 2006 at 9:23 pm

use system command.

ex: calling_script.pl
/usr/bin/perl -w

printf(“%s\n”,”this is calling script”);

system(“/myhome/caller_script.pl”);
exit;

Reply

Nilesh October 31, 2007 at 7:15 am

Hi, I am calling 1.pl from main.pl file.
using
#main.pl
system (“perl 1.pl”);

In this case it works fine. But when I am doing

#main.pl
system (“perl 1.pl”);
system (“perl 2.pl”);

then it doesn’t executes “1.pl” properly.
So I would like to know, is there any constraint for this? Do I need to take any precautions for this?

Thanks,

Reply

Gangadhar February 21, 2008 at 7:12 pm

actually i want the CVS tool in Perl ,i want write one programthat is Add which are we used in CVS ,so how i could write that program in perl

Reply

Chris March 11, 2008 at 5:23 pm

How can I call a sister perl script inside a perl script using Expect.pm. When the perl expect ends the script exits never executing the other script even though my last line in the script is

@myarray=`/usr/bin/perl /myscript.pl`;
print $myarray;

Reply

Amit gupta June 23, 2008 at 7:04 am

how do i run perl script in window xp or in dos

Reply

vijay October 5, 2009 at 10:26 am

in one program i am using system command in that i called another program it is in some other drive how can i fix ths problem

Reply

Pankaj January 14, 2010 at 5:46 am

Hi,
I want to write into file by calling another perl/cgi script.
sample1.cgi

#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
use Switch;
print qq'
Field Name :
';

from sample1.cgi I m trying to call sample2.pl

sample2.pl

#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI;
use Switch;
my $field="AVATAR";
open NEW_FILE,">/tmp/test.dat";
print NEW_FILE "$field";
close NEW_FILE;

When I m executing sample2.pl this works fine, This is able to write a word “AVATAR” into file but when I m using sampe1.cgi I doesn’t work as same.

Reply

Leave a Comment

What is 4 + 7 ?
Please leave these two fields as-is:
Solve the simple math (so we know that you are a human)

Previous post:

Next post: