executing perl script from another perl script : NOT WORKING

Hi Folks,

I have 2 perl scripts and I need to execute 2nd perl script from the 1st perl script in WINDOWS.

In the 1st perl script that I had, I am calling the 2nd script

main.pl

print "This is my main script\n";
 `perl C:\\Users\\sripathg\\Desktop\\scripts\\hi.pl`;
 
 
hi.pl   ( this script I am calling from the firstperlscript.pl)

====

#!perl -w
print "hii Giridhar....\n";

what my problem is after executing the main.pl, it is just opening the physical hi.pl(this script that I am calling from main.pl) but the hi.pl is not executed. I want the hi.pl to be executed from the main perl script i.e., the hi.pl output has to be displayed along with main.pl code.

Guys, Could you please provide your valuable suggestions here.

I have tried the below syntax from main.pl script as well but none of them worked for me

syntax 1:

system ('start C:\\Users\\sripathg\\Desktop\\scripts\\hi.pl'); 

syntax 2:

$output = `C:/Users/sripathg/Desktop/scripts/hi.pl`;
print $output;

In windows, it will start a new command prompt and execute your script.

So, you cannot capture the output in same window.

create function and call the function in the same script.

use code tag while posting the data or scripts

 
`perl C:\\Users\\sripathg\\Desktop\\scripts\\hi.pl`;

Thanks kamaraj for your prompt response.

As you mentioned we can create function and call the function in the same script, but Is there a way to call(i mean to execute) another perl script from the main script in WINDOWS.

My requirement is in such a way that I need to pass value to another perl script from the main script.

And the code that you mentioned, it looks same that I have written in main.pl code.

Could you please provide your suggestions in this scenario ?

in that case, redirect all the ouput of second script to some file and once it got executed, read the file in your first script and do the necessary action.

otherwise, refer this post

ipc - How do I run a Perl script from within a Perl script? - Stack Overflow

1 Like