Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have the following PHP code that I want to use to call a python script (ring.py)

  <?php echo '<p>Hello World</p>'; 
    $output = exec('python ring.py');
  ?> 

The program ring.py creates 2 files. When I run the PHP script from command line:

php index.php

then the php script correctly runs the python script and 2 files are created as desired.

However when someone accesses the PHP page through a web browser, it doesn't seem to run the python script and no files are created. How can I fix this?

Thanks so much!

share|improve this question
check for errors using if(!$output) and print the error – Aswin Murugesh 6 hours ago
how do I print the error exactly? – tree-hacker 5 hours ago
die(exec_error) will do – Aswin Murugesh 4 hours ago
possible duplicate of Getting PHP to run a Python script – fearphage 3 hours ago

2 Answers

You should do chmod 0777 ring.py, because just doing +x will affect just your user. Normally, PHP is executed by another user (usually, anonym), that probably is not in the same group as yours.

share|improve this answer

Make sure the Python script on the server is executable

chmod +x ring.py

and make sure it's either in the same directory as the PHP script or use the full path.

share|improve this answer
yes I tried that already and it works when I run the php script from command line so that's not the issue. Its just it doesn't work when someone accesses the php script through the web browser. Any idea why? – tree-hacker 5 hours ago
stackoverflow.com/questions/2219982/… here's a similar question that might be of help. – Tobi Hahn 5 hours ago

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.