1

I'm trying to execute a perl script from php. That perl script is reading a webpage and producing an xml file with some data. If i exec it via shell everything works as expected but when I'm trying to automate the whole thing via php nothing works.

I've tried this:

exec("perl /absolute/path/to/perl/script/parser.pl", $output, $result);

when i echo the $result variable it displays 2. I've switched the php safe_mode On and Off several times but nothing changed. Also tried to set the safe_mode_exec_dir without positive results.

When i exec a simple ls

exec("ls", $output, $result);

everything goes well, i get the list of files and $result is 0.

The perl script has chmod 777 so that it would not be a problem of permission. Also his folder has 777.

I'm almost sure that the issue is something about the server but I'm not able to find out what.

Any help would be really appreciated.

Thanks

4
  • When can parser.pl return 2? Are you sure you're running the script with the correct arguments? Is there anything in $output? And your example is missing an end double quote. Commented Feb 23, 2011 at 23:04
  • the script doesn't have any argument, i've tried to copy/paste as it is written above (obviously with the right path) into the shell and it works. You are right the example is missing a quete but is just a problem of copying the code inside SO, sorry. Commented Feb 23, 2011 at 23:07
  • $result should contain the status of the executed command which seems to be 2, but i don't know what it means Commented Feb 23, 2011 at 23:10
  • 2
    Does this work if you use a trivial perl script (exit(0);, for example)? That will let you know if it's something in your Perl script, or if its that you're not able to execute Perl at all. Commented Feb 23, 2011 at 23:19

2 Answers 2

4

You probably need to specify the full path to your perl executable.

Try typing which perl to see what the full path is, then place that full path in your exec call.

Sign up to request clarification or add additional context in comments.

Comments

1

Your example seems to be missing the end quote for the first argument. I would also make sure that the executable for perl is in your path. Lastly, not only does the folder need to have the execute bit set, but all of the directories up to root need to be set to allow perl to access the script. It is fairly common for a directory to be 750 such that a group can get in, but not the world. As a user you may be able to cd there and see the script, but you must look at it from the perspective of the users that is executing the script -- presumably the id your webserver is running as.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.