php - 无法使用 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 上打开,这是我的默认文本编辑器。
解决方案
推荐阅读
- python - 如何计算熊猫数据框中的频率项?
- r - 计算二项分布概率时的 NaN 值
- java - java.lang.NoSuchMethodError: 没有虚拟方法 getToken(Z)
- python - 如何使用 os.system(或替代方法)远程关闭任何系统?
- javascript - React & Material UI - 如何删除基于路由的导航按钮/链接?
- regex - Perl 在替换本身中进行替换
- json - 将 JSON 存储到数组中
- python - 从字符串(或 DataFrame 对象)中提取时间数据的更有效方法
- .net - Windows 社区工具包的 WPF IUriToStreamResolver 实现?
- django - 错误未记录到 txt 文件