pythonphppython-3.xweb

Php shell_exec() not running python script


I am trying to run a python script from php code. I have followed other threads to see what I'm doing wrong, but i can't seem to find the problem.

$out = shell_exec(escapeshellcmd("/path/to/script/here/script.py arg1 arg2"));
echo $out;

As you might ask, yes, the script:

  1. has "#!/usr/bin/env python3" added
  2. has permission to be read and executed by group www-data (from output apachectl -S)
  3. is executable

At the same time, any other non-script command works just fine with shell_exec()


Solution

  • I tried your code, it is working fine for me. If there is some error, it must be logged in error.log file. e.g. I am using apache so my errors are logged in /var/log/apache2/error.log