我在从 Codeigniter Controller 的函数执行 Python 文件时遇到了一些问题。
~/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 &');
}
}
但是当我尝试执行系统调用时,例如:
system("sudo gpio mode 15 out");
这非常有效。
请您参考如下方法:
提供python二进制文件和脚本的完整路径,即:
system('/full/path/to/python /full/path/to/test.py > /dev/null 2>/dev/null &');
如果 python 二进制文件已经在您的 apache 用户的 PATH 中 (apache/www-user ), 你可以忽略完整路径。
