I have a python code and I want to execute it from my php. I have seen all the other questions. But my problem is that I am not getting proper directory path. My test python code is,
a=4
b=5
return a+b
I was making a small html like,
<!DOCTYPE html>
<html>
<body>
<?php
$result = exec("python test.py");
echo $result;
?>
</body>
</html>
I was running it from wamp server. So I put both of them in www folder. Their urls are C:\wamp\www\test.py C:\wamp\www\1.php. I have installed python in my C: drive. So what is the proper path setup? And do I have to update my Apache server settings for python running?
in your python code you must have a print not return, and in php code try to use absolute path. Python
a=4;
b=5;
print a+b;
PHP
<?php
$result = exec("C:\\Python27\\python.exe C:\\xampp\\htdocs\\test.py");
print_r( $result);
?>
or
<?php
$command = escapeshellcmd('C:/xampp/htdocs/test.py');
$output = shell_exec($command);
echo $output;
?>