duanliu8998 2014-02-03 04:45
浏览 46
已采纳

从php运行python程序

I have python file in /usr/local/bin I can run it anywhere in server using addid.py --id [id]

And now I need to run it from php file: add.php?id=[id]

<?php
$id = $_GET["id"];
$command = "addid.py --id $id";
$job = shell_exec($command);
echo $job;
print '<hr/>';
print $command;
?>

Page loads faster, but python program actually works longer (~30 seconds). Also cannot see python program in htop (task manager). It prints < hr > line and result of $command (string).

Also added export PATH=$PATH:/usr/local/bin to /etc/sysconfig/httpd

What is wrong?

  • 写回答

1条回答 默认 最新

  • douxiangdiao6348 2014-02-03 05:50
    关注

    The command needs to invoke the python interpreter, right now it is just a file name.

    $id = escapeshellarg($_GET["id"]); 
    $command = "python addid.py --id $id";
    $job = shell_exec($command);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题