Executing a python file from PHP - Linux -


i have python file want execute whenever php page called. python file in same folder php file. python script on execution edits textfile php file accesses.

i have following code:

<?php  exec("python somefile.py",$output); $file = fopen("test.txt",'r'); .... 

for reason, python script never gets executed. know can see changes in text file. since not sure if script made executable, included "python" on command. ran:

chmod +x somefile.py 

just make sure not reason. did not too. should change make php page execute python script whenever called?

this permission issue.

try

echo exec("whoami"); 

this let know php running as. need verify user can run python script. if file not created same daemon runs python, denied permission.

update

this let know owns files working with. file being written needs writable user running python. if running python ssh, not same user when run python exec.

echo exec('whoami') . "<br>"; echo exec("ls -l test.txt") . "<br>"; echo exec("ls -l somefile.py") . "<br>"; 

update 2

because forget exists.

passthru('python somefile.py 1 2>&1'); 

this exec python file, , output stderr stdout.


Comments