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), then it works fine.

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 checked it with this command:

which python
ls -lisa /usr/bin/python

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

Similarly I also used this command:

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?

  • Executing an external script in Drupal is not different from executing it from PHP, as Drupal doesn't have specific functions.
    – apaderno
    Aug 21, 2011 at 11:49

2 Answers 2


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!



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.

Your Answer

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

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