I've got a simple PHP script that is using shell_exec to call a python script which should return the result "ok"
I can't seem to get this working - nothing is returned via the php file. I can run a python script from the CLI and it works, and also run shell_exec to rn other functions and that works. So its something specific to python which I can't work out.
test.py:
#!/usr/bin/python3
import sys
id = sys.argv[1:]
#Do some stuff wih id
#Return success
sys.exit("ok")
index.php
<?php
$command = escapeshellcmd('/root/bin/tracker/test.py');
$output = shell_exec($command);
echo $output;
//This works
//$output = shell_exec("cat /etc/os-release");
//echo $output;
?>
Running /root/bin/tracker/test.py returns:
ok
I've tried setting ownership of test.py to www:www-run and also checked +x permissions.
This is running on SLES 15.1 PHP 7.2.5 Apache 2.4.33
/path/to/python /root/bin/tracker/test.py.sys.exit("ok")indicates an error, according to the docsshell_execreturnsnullwhen a error occurs. Usesys.exit(0)for success.