| 2 comments ]

Running a perl script from PHP
I have tried to run a perl script from my php file. The perl script was running in command line and worked well.
But when I tried to execute the same form my php script, it was not working . I have tried the same with the other possibilities system, passthru, shell_exec, exec, etc. I have used the following commands.

shell_exec("perl filename.pl arg1");
shell_exec("user/bin/perl filename.pl arg1");

I have tried out with both paths of perl script and perl compiler and even tried with out path of compiler. But no luck :(..result was the same

Do you face the same problem? Try out the following.I have tried the same and my perl script worked well from php

* Turn On the safe mode settings in your php.ini file
You need to check whether the safe mode is ON in your php settings( php.ini).
You can use phpinfo() to check the same . If it is set OFF please set it as ON.
This is needed to run the shell execution commands in php.

* Check permission of perl script
It is required to give give all permissions to web server on the perl script (user owner and user group). if your web
server is apache, you need to set the user owner and user group to apache.Now the peal script execution from php will work. if you have the sudo permission you can do it yourself.

if you run the system("perl filename.pl arg1"); with out proper permission it will return an error code 13, which is related to the file permission.

Now your perl script will work fine from php . you can try it out with all execution commands .

passthru("perl filename.pl arg1");
exec("perl filename.pl arg1");
or $var = `perl filename.pl arg1`;


I hope this will help someone else which is my reason for sharing

enjoy scripting .....

Please comment me regarding on the post.

2 comments

v!N!th@ said... @ Friday, May 22, 2009 at 9:44:00 AM GMT+1

Hello Jey Jey :)

all of your blogs are very informative
Keep writing..
expecting more informative blogs from you

Thank you :)

Anonymous said... @ Thursday, March 1, 2012 at 8:36:00 PM GMT

Thank you so much it saves a lot of time and keeping blood pressure low......

Keep up the good work

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.