Reputation: 79
I've got my website hosted at one.com and I'd like to run a simple python script with php that returns 'hello' but I get no result. It worked perfectly on local with Mamp. What should I configure for it to work online ?
My php code:
<?php
$result = shell_exec('python test.py');
echo $result;
?>
The python script
print('hello')
Upvotes: 0
Views: 1233
Reputation: 61
First of all make sure that the python script is executable on the server. For safety reasons I would remove the space in the filename as well so make it just test.py for now. You can make it executable by simple changing the permissions using chmod +x test.py
Then, you can try the following lines of code in php
<?php
$command = escapeshellcmd('/usr/custom/test.py');
$output = shell_exec($command);
echo $output;
?>
Upvotes: 1