【问题标题】:php shell_exec command doesn't give an outpu of the python scriptt in ubuntuphp shell_exec 命令在 ubuntu 中没有给出 python 脚本的输出
【发布时间】:2019-09-12 10:52:07
【问题描述】:

我正在尝试使用 shell_exec 命令从 php 调用 python 文件。但是 shell_exec 没有给出任何输出。

我在终端上运行 python 脚本,它给了我正确的输出

  python3 var/www/html/thilina/assets/documents/threadsearch.py keyword,equipment_types/2

这就是我在控制器中调用 python 脚本的方式

  $key = $this->input->post('search');//from ajax       
  $fnum = $this->input->post('sub');//from ajax      
  $sym = $key.",".$fnum;//search key + 2   
  $chk = FCPATH."/assets/documents/threadsearch.py";
  $chk = str_replace('\\', '/', $chk);
  $output = shell_exec("python3 $chk $sym");//get the output from python script

【问题讨论】:

标签: php python python-3.x codeigniter ubuntu


【解决方案1】:
  1. 尝试通过将2>&1 附加到命令来捕获错误流:$output = shell_exec("python3 $chk $sym 2>&1"); 请参阅PHP - How to get Shell errors echoed out to screen

  2. 您可能存在操作系统命令注入漏洞(您将用户输入与 shell 命令连接)。见https://portswigger.net/web-security/os-command-injection

【讨论】:

    猜你喜欢
    • 2016-10-06
    • 1970-01-01
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    相关资源
    最近更新 更多