LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2012, 07:36 AM   #1
nuwan.rathnayake
LQ Newbie
 
Registered: Aug 2012
Posts: 10

Rep: Reputation: Disabled
calling a perl script using php script


Friends,
I want to call a perl script using php script. I have test.php and test.pl in /var/www/html. what are the contents of them...
thank you
 
Old 08-08-2012, 07:39 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
system a possible solution. Or exec.
 
1 members found this post helpful.
Old 08-08-2012, 08:16 AM   #3
nuwan.rathnayake
LQ Newbie
 
Registered: Aug 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
thank you very much sir and one another thing..
this is what i have written

this is test.pl
Code:
<?php
Echo "\n";
Echo "\n";
Echo "Hello World_im php!";
Echo "\n";
Echo "\n";
echo exec('sudo perl /var/www/html/test.pl');
 ?>

this is test.php

Code:
#!/usr/bin/perl


print "\n";
print "\n";
print "Hello World_im perl\n";
print "\n";
print "\n";
when i run test.php the output was

Hello World_im php!


is my perl program executing and if it is so how can i take the output of the perl program (here Hello World_im perl ) to the command prompt?
 
Old 08-08-2012, 08:50 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Please don't tell me that you have written a script that is capable of doing a sudo ...

That's a loaded gun you're holding, there! Don't you value your foot?
 
1 members found this post helpful.
Old 08-08-2012, 09:15 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Yes, repeat this test without sudo.
 
1 members found this post helpful.
Old 08-08-2012, 10:54 PM   #6
nuwan.rathnayake
LQ Newbie
 
Registered: Aug 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
oh .but even without sudo it did not work.anyhow now its working.....thanks for your help friends..

i am trying to pass a variable to perl script from php script. ill contact you again in a case where i face troubles again.
 
Old 08-08-2012, 11:32 PM   #7
nuwan.rathnayake
LQ Newbie
 
Registered: Aug 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
got one....

these are my scripts.
php
Code:
<?php
$var1 = "ABC";
exec("perl myScript.pl $var1", $output);
print_r($output);
?>
perl

Code:
#!/usr/bin/perl
$var1 = $ARGV[0];
print "VAR1: ".$var1."\n";

why is this not working?
 
Old 08-09-2012, 12:58 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I would guess to start with you need the full path to perl
Code:
exec("/usr/bin/perl myScript.pl $var1", $output);
 
Old 08-09-2012, 02:24 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,864
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
"Not working" is not enough -- give the exact error-message.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
calling a shell script present on another server using perl script. anandg111 Linux - Server 4 07-18-2012 12:23 AM
how to pass variables to perl script from php script smohan Programming 17 06-17-2010 08:15 AM
Calling perl script and passing variable from php script hosea Programming 5 10-21-2008 08:01 AM
calling a c++ binary inside a perl script Blue_muppet Programming 3 08-28-2004 11:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration