首页 > 解决方案 > 无法使用 shell_exec 在本地服务器上的 php 上执行 python 文件

问题描述

我试图在 php 上执行 .py 文件。我已经通过 anaconda 3.7 安装了我的 python

我尝试使用 shell_exec 命令,但它不执行 .py 文件的输出。它只是在 sublime 中打开 .py 文件。

#the output should be test
print ("test")

.py 文件保存 test.py

<?php
$command = escapeshellcmd('test.py');
$output = shell_exec($command);
echo $output;
?>

.php 文件另存为 cb.php

我把它们放在同一个名为 test 的文件中,在 htdoc 中。我键入http://localhost/test/cb.php在浏览器上运行 php 文件。我希望 .py 代码应该被执行并且 php 文件应该输出“test”但是 test.py 文件只是在 sublime text 上打开,这是我的默认文本编辑器。

标签: phppython-3.xxamppshell-exec

解决方案


推荐阅读