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;
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突