Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm trying to execute a python script from drupal using this:

exec('/usr/bin/python name_of_the_script.py')

But it does not work

Although, if I'm on the php console (php -a), it works.

The "name_of_the_script.py" file has all the permissions.

I thought maybe it was the "python" command that didn't have all the permissions.

So I check it like this

which python
ls -lisa /usr/bin/python

694 0 lrwxrwxrwx 1 root root 9 2011-03-09 18:41 /usr/bin/python -> python2.6

ls -lisa /usr/bin/python2.6

369 2240 -rwxr-xr-x 1 root root 2288240 2010-04-16 10:06 /usr/bin/python2.6

It seems everything is OK.

Do you have any suggestions?

share|improve this question
Executing an external script in Drupal is not different from executing it from PHP, as Drupal doesn't have specific functions. – kiamlaluno Aug 21 '11 at 11:49

2 Answers

up vote 1 down vote accepted

Adding 2>&1

exec('/usr/bin/python script.py 2>&1');

Pointed me to the right direction.

I was writting in a file ( inside the script that hadn't enough permissions )

chmod 666 name_of_the_file.txt totally solved the issue!

Thanks!

share|improve this answer

Most likely it's a permission of your webserver that is causing this. You should take care as things could turn out badly should your drupal site be compromised.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.