Run python script with php exiting

Are there any special permissions or settings for executing a python script that create a new file or image? This is my code:

<?
function py(){
    exec( 'python my_script.py');
    echo "ok";
}

py();
?>

And this is my python script (example):

#!/usr/bin/python
import sys

f = open('out.txt', 'w')
print >> f, 'thats all'
f.close()

Running php I get the message "ok", but the file is not created. What am I doing wrong?

+4
source share
2 answers

Setting permissions on files and folders did the trick.

enter image description here

On Mac OS: Alt + Press "+", then search _www and add the World Wide Web Server to read and write users. The same goes for the root folder.

+1
source

You need to call shell_exec()not exec()if you want to write the output:

Refernce: PHP

0

Source: https://habr.com/ru/post/1655113/


All Articles