I'm experiencing a weird problem in trying to execute python in a php server (LAMP). (safe_mode off)
if I type:
$output = shell_exec("ls -lah");
echo "<pre>$Output</pre>";
I got the result of the ls
command. Same for$output = shell_exec("tar --version");
and other applications, such as gzip.
However, if I switch for any of these lines:
$output = shell_exec("python --version");
$output = shell_exec("python2.7 --version");
$output = shell_exec("/usr/bin/python --version");
$output = shell_exec("python my_script.py");
And other variants of this kind, I get no results. The command is not being executed, the python bitecode not made and the echo
remains silent.
I have also tried with the exec()
command with no more success.
I think this may help...
looks like the output for the python call needs to be routed properly. I was able to make this work within my index.php file for returning the python version...
shell_exec("python -V 2>&1");
Here is where I found the answer.
If you are trying to run the python script using the following code
$output = shell_exec("python my_script.py");
you will need to use absolute path for my_script.py and give all permissions (I am not sure which ones are sufficient) for the python file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With