BenYacine BenYacine - 2 years ago 263
Python Question

Executing a Python file from Codeigniter

I have some trouble to execute a Python file from a Codeigniter controller's function.

~/application/controllers/Lights.php :

header("Access-Control-Allow-Origin: *");
class Lights extends CI_Controller {
public function __construct() {
parent::__construct ();
$this->load->helper ( array ('url', 'form') );
public function turnOn() {
system('sudo python > /dev/null 2>/dev/null &');

but when I try to execute a system call, like :

system("sudo gpio mode 15 out");

this works perfectly.

Answer Source

Provide the full path to python binary and script, i.e.:

system('/full/path/to/python /full/path/to/ > /dev/null 2>/dev/null &');

If the python binary is already on the PATH of your apache user (apache/www-user), you may ignore the full path.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download