Search code examples
phppythonwebserver

Run python script from php on webserver


I have a free webspace hosted by altervista where i have one script python and one script php. What i want to do is call the python script using the php script. I googled for a solution and i found several questions about it, i tried different proposed solutions but no one worked for me.

Here the php script code:

<?php 

$command = escapeshellcmd('test.py');
$output = shell_exec($command);
echo $output;

?>

and here the python script code:

print("Hello")

When i run the php script nothing happens. What's wrong?

Thanks


Solution

  • Your hosting company might have disabled the shell-exec function for security reasons. I'm not saying it is the case, but you should check that first before even trying to run shell_exec.

    Seealso: PHP - How to know if server allows shell_exec

    Plus, back in 2012, it wasn't possible with Altervista...