0

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')
Nicolas Vriak
  • 79
  • 2
  • 10
  • have you got #!/usr/bin/env python or your path to python at the top of the file to make it executable. Also check that the python file has 755 permissions – pastaleg Nov 21 '17 at 22:17
  • It's probably disabled https://stackoverflow.com/questions/21581560/php-how-to-know-if-server-allows-shell-exec – Oleg Nov 21 '17 at 22:21

1 Answers1

1

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;

?>
user8981117
  • 61
  • 1
  • 7