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.

8
  • Missing info: PATH, execution bit, stderr, errno. Commented May 20, 2019 at 5:33
  • there are no error, everything seems fine. when i execute the .php file its just blank and open the .py file Commented May 20, 2019 at 5: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 Commented May 20, 2019 at 5:42
  • stackoverflow.com/questions/13326181/… 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. Commented May 20, 2019 at 5:56
  • Why don't you just invoke the script as you would in cmd? Commented May 20, 2019 at 6:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.