0

im trying to execute .py file on php. Ive installed my python through anaconda, 3.7

ive tried to use shell_exec command but it doesnt execute the output from .py file. its just open the .py file in sublime.

#the output should be test
print ("test")

the .py file saved test.py

<?php
$command = escapeshellcmd('test.py');
$output = shell_exec($command);
echo $output;
?>

the .php file saved as cb.php

i put them on the same file named test, in htdoc. i type http://localhost/test/cb.php to run the php file on the browser. I expect the .py code should be executed and the php file should output "test" but the test.py file just opened on sublime text which is my default text editor.

yuliansen
  • 470
  • 2
  • 14
  • 29
  • Missing info: PATH, execution bit, stderr, errno. – mario May 20 '19 at 05:33
  • there are no error, everything seems fine. when i execute the .php file its just blank and open the .py file – yuliansen May 20 '19 at 05:40
  • 1
    If this is on Windows, the script may not be executed unless you also specify the interpreter. Else e.g.: [Running Python script from command line opens script in the default text editor instead of executing script](//stackoverflow.com/q/13326181) – mario May 20 '19 at 05:42
  • https://stackoverflow.com/questions/13326181/running-python-script-from-command-line-opens-script-in-the-default-text-editor im sorry but i dont understand any of these. i tried this part > assoc .PY=Python.File > ftype Python.File=c:\Program Files\Python\2.7\python.exe "%1" %* this happened: Access is denied. Error occurred while processing: PY. – yuliansen May 20 '19 at 05:56
  • Why don't you just invoke the script as you would in cmd? – mario May 20 '19 at 06:59
  • it works, like a charm, i manually change the default app to open python. it was sublime then i change it to python.exe – yuliansen May 22 '19 at 03:27
  • You could use `shell_exec("python.exe test.py")` rather. – mario May 22 '19 at 09:03
  • i was using shell_exec("python test.py" it wasnt work, it wasnt even open the file on sublime. is there any differences – yuliansen May 23 '19 at 10:07

0 Answers0