executing perl script from another perl script : NOT WORKING


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting executing perl script from another perl script : NOT WORKING
# 1  
Old 08-03-2012
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
===========

Code:
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)

====
Code:
#!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:
Code:
system ('start C:\\Users\\sripathg\\Desktop\\scripts\\hi.pl');

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

Moderator's Comments:
Mod Comment Code tags for code, PLEASE!

Last edited by Corona688; 08-03-2012 at 11:47 AM..
# 2  
Old 08-03-2012
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

https://www.unix.com/how-post-unix-li...code-tags.html


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

# 3  
Old 08-03-2012
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 ?
# 4  
Old 08-03-2012
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
This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in executing select query from perl script

Hi, I have a perl snippet that call a select query with a bind variable,when i compile the script I'm unable to get the query output. The same query when i fire in sqlplus fetches few rows. The query takes bit time to fetch results in sqlplus. my $getaccts = $lda->prepare("select distinct ... (1 Reply)
Discussion started by: rkrish
1 Replies

2. Shell Programming and Scripting

Problem executing perl script on remote server

Hello, I am running in to a problem running a perl script on a remote server. I can run a simple script test.pl which contains just a print statment without issue by running ssh root@1.2.3.4 perl test.pl However, I have a more complex script that does not execute as expected. I think I... (3 Replies)
Discussion started by: colinireland
3 Replies

3. Shell Programming and Scripting

Error in executing Perl script

Hello All I am facing an issue The unix script is running fine in unix environment which uses ssh connection but when I try to run the same in informatica environment (same server where I was running the unix script manually successfully) its showing the below error command-line line 0:... (11 Replies)
Discussion started by: Pratik4891
11 Replies

4. Shell Programming and Scripting

Executing AWK in a perl script using 'system'...

I have a simple perl script that looks similar to this: #!/usr/bin/perl/ # Have a lot of PERL code in the front of this script. #Would now like to execute a system command using AWK system (qq(cd /location && awk '/full/ {print $1;exit}' /myfile)); The system command in my perl script... (4 Replies)
Discussion started by: SysAdm2
4 Replies

5. Shell Programming and Scripting

Executing program with Perl script but needs user input

Hello, I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this? Thanks (1 Reply)
Discussion started by: leonard2352
1 Replies

6. Programming

Date time problem while executing perl script.

Hi All, This Monday 15th March 2010, i have faced a weired issue with my Perl script execution, this script is scheduled to run at 1 minute past midnight on daily basis ( 00:01 EST ) generally for fetching previous business date , say if it is Monday it should give last Friday date, for Tuesday... (0 Replies)
Discussion started by: ravimishra
0 Replies

7. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

8. Shell Programming and Scripting

Perl script not executing

Hi All, I have been given a perl script to modify but which is not running completely.And it is not showing any errors also. The script is : #!/usr/local/bin/perl print "Which transaction? "; print "\n"; print "1 - Inquiry"; print "\n"; print "2 - Delete Bank"; print "\n"; print... (8 Replies)
Discussion started by: usha rao
8 Replies

9. Shell Programming and Scripting

Executing .profile from perl script

Hi, How can i execute .profile from a perl script I need this - i am trying to run perl script from crontab and it looses the environment variables Please provide help Your help is greatly appreciated Thanks (1 Reply)
Discussion started by: prekida
1 Replies

10. Shell Programming and Scripting

Problem executing setuid script in perl-5.8.6

Hi, I have a script (a.pl) that can be run by anyone. The script internally has to read a file and write into few files which are owned by user 'myUser'. Has to read the following file: -rwx------ 1 myuser myuser 4986 Aug 20 18:11 my.file Has to write into following files: ... (0 Replies)
Discussion started by: sarmakdvsr
0 Replies
Login or Register to Ask a Question