Is there any special permission or setting in order to execute 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 (an example):
#!/usr/bin/python
import sys
f = open('out.txt', 'w')
print >> f, 'thats all'
f.close()
Running php i get "ok" message but no file is created. What am i doing wrong?
asked Sep 19, 2016 at 18:18
slash89mf
1,0672 gold badges13 silver badges36 bronze badges
2 Answers 2
Setting the right permissions to file and folders did the trick.
On Mac OS: Alt + Click on "+", then search for _www and add World Wide Web Server to users giving read and write permission. Same for the root folder.
answered Sep 20, 2016 at 7:42
slash89mf
1,0672 gold badges13 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You need to call shell_exec() not exec() if you want to be able to capture the output:
NSNoob
5,6166 gold badges44 silver badges58 bronze badges
answered Sep 19, 2016 at 20:16
Mike Mannakee
3611 silver badge6 bronze badges
default
www-user. So the Python script would be stared from the same user. Doeswww-userhas the desired permissions to execute the Python script and access file-system for file-creation?www-useryou could either change the user towww-useror pass the desired user name to theexeccommand as shown here