【发布时间】:2017-05-12 20:28:20
【问题描述】:
我有一个连接到数据库的 PHP 脚本。以下数组背后的想法是将此信息插入到数据库中。类别需要由 ML 算法设置,为此我使用 textblob for Python。我正在使用 codeigniter PHP 框架。
$temp = $this->input->post('issue');
$data = array(
'priority' => '1',
'Summary' => $this->input->post('issue'),
'status' => 'Submitted',
'category' => exec("python machineLearning.py .$temp"),
'itemsRequired' => ' ',
'lastUpdate' => date('Y-m-d G:i:s'),
'ownerID' => $this->session->userdata('username'),
'managerID' => 'tech'
);
python 脚本 (machineLearning.py) 在单独调用时可以正常工作。我得到的错误是该类别当前保留为空字符串。我尝试使用以下测试:
exec("python machineLearning.py idCard", $output);
print_r($output);
但结果只是一个空数组:
数组()
python 程序在名为 machineLearning 的函数中包含机器学习,并接受一个名为 issue 的参数。我需要传递的值
$this->input->post('issue')
进入python程序中的machineLearning函数。我是否错误地传递了参数,或者 exec() 函数是否需要正确的程序路径?谢谢大家。
找到解决方案
两个当前参数的组合解决了这个问题,我必须更新文件路径,在 exec() 函数内部,并更新 exec function() 的参数部分,但必须另外使用if 语句建议。谢谢两位的帮助
【问题讨论】:
-
我强烈建议在 shell 命令中使用之前转义/清理用户输入。现在有人可以发布恶意问题,例如
; rm -Rf . -
@Devon 我听说过这个,但目前正在努力让这成为可能。不过,为了将来参考,我该怎么做?
-
php中有一个函数escapeshellarg,应该会派上用场。
标签: php python codeigniter python-3.x php-7