PHP shell_exec在终端中工作,但在网页上不显示输出

时间:2018-04-29 01:45:18

标签: php python scripting shell-exec

正如标题所说,我使用shell_exec从PHP运行python脚本,这通过运行'php ./python.php'从SSH会话运行到我的Web服务器时起作用。我得到了预期的输出。

然而,当页面加载到Web浏览器上时,我只是得到一个没有PHP警告或错误的空白网页。任何帮助表示赞赏。

python.php:

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

ini_set('memory_limit', '-1');

$command = escapeshellcmd("python3 ./test.py 2>&1");
$output =  shell_exec($command);
echo $output;


?>

test.py:

#!/usr/bin/env python


import pandas as pd
import math
import csv

url = 'https://afltables.com/afl/stats/2018a.html'
dfs = pd.read_html(url)
dfs = dfs[1]

dfs.to_csv('hmm.csv', sep=',', encoding='utf-8');
dfs = dfs[dfs.TM == "NM"]
dfs = dfs[dfs.GM > 3]

url = 'https://afltables.com/afl/seas/2018.html'
lad = pd.read_html(url)

scores = []


for index, row in dfs.iterrows():
    score = (math.sqrt(row['CP']) * 2 + (row['IF']) * 2 + (row['CL']) ** 2)
    scores.append([row['Player'], score])

pos = 1
scores = sorted(scores, key=lambda x: x[1], reverse=True)
for item in scores:
    print(str(pos) + ". " + item[0] + ": " + str(item[1]))
    pos = pos + 1

0 个答案:

没有答案