dongzhoutuo0883 2016-04-14 18:19
浏览 64
已采纳

从PHP调用Python脚本

I am trying to call a python script from my PHP page but no output is being delivered. Is there any error in code ?

<?php
include('main.php'); 
$lat = $_POST['lt'];
$lon = $_POST['ln'];
$uid = $_POST['id'];
$rad = $_POST['rd'];

$outs = 'python recommend.py ' . $uid . ' ' . $lat . ' ' . $lon . ' ' .     $rad;
$output = shell_exec($outs);
echo $output;
?>

Whereas I tried to get the output using dummy variables, it is being shown.

<?php
$lat = $_POST['lt'];
$lon = $_POST['ln'];
$uid = $_POST['id'];
$rad = $_POST['rd'];
echo        "11,28.720663,77.106192,1.18764869157,50.2058551405~12,28.705344,77.147270,2.854    76982119,2.42050298022~14,28.697590,77.143108,2.63211107261,13.1314821232~64,28.        683058,77.079048,2.10283926574,28.9526789043~66,28.670294,77.126684,2.8317092358    ,5.80484607006~67,28.677712,77.092713,1.95077211146,28.4871314757~68,28.665512,7    7.093081,2.76955528898,21.8407451837~71,28.674069,77.124547,2.53467055409,24.755    4907651~"
?>
  • 写回答

1条回答 默认 最新

  • duanpin2009 2016-04-14 18:31
    关注

    My guess is that you need to provide the full path to the python script, i.e.:

    python /full/path/to/recommend.py
    

    As mentioned on my comments, in order to properly debug php, you'll need to enable error reporting at the top of your php scripts , i.e.:

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    //the rest of your code...
    

    Comment on production mode.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵