从Codeigniter执行Python文件 [英] Executing a Python file from Codeigniter
本文介绍了从Codeigniter执行Python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从Codeigniter控制器的功能执行Python文件时遇到麻烦.
I have some trouble to execute a Python file from a Codeigniter controller's function.
〜/application/controllers/Lights.php:
~/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 test.py > /dev/null 2>/dev/null &');
}
}
但是当我尝试执行系统调用时,例如:
but when I try to execute a system call, like :
system("sudo gpio mode 15 out");
这很好用.
推荐答案
为 python
二进制文件和 script
提供完整路径,即:
Provide the full path to python
binary and script
, i.e.:
system('/full/path/to/python /full/path/to/test.py > /dev/null 2>/dev/null &');
如果您的apache用户( apache
/ www-user
),则可以忽略完整路径.
If the python
binary is already on the PATH
of your apache user (apache
/www-user
), you may ignore the full path.
这篇关于从Codeigniter执行Python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文