dousi1875 2017-11-21 22:15
浏览 86

在Web服务器上使用php运行python脚本

I've got my website hosted at one.com and I'd like to run a simple python script with php that returns 'hello' but I get no result. It worked perfectly on local with Mamp. What should I configure for it to work online ?

My php code:

<?php
$result = shell_exec('python test.py');
echo $result;
 ?>

The python script

print('hello')

</div>
  • 写回答

1条回答 默认 最新

  • donglankui1263 2017-11-21 22:20
    关注

    First of all make sure that the python script is executable on the server. For safety reasons I would remove the space in the filename as well so make it just test.py for now. You can make it executable by simple changing the permissions using chmod +x test.py

    Then, you can try the following lines of code in php

    <?php 
    
    $command = escapeshellcmd('/usr/custom/test.py');
    $output = shell_exec($command);
    echo $output;
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度