php - 在 PHP 中正确打印 python 脚本输出

标签 php python

我有一个 php 文件调用脚本并像这样打印输出


    $output=shell_exec('/usr/bin/python hello.py');
    echo $output;

它打印;


    b'total 16\ndrwx---r-x 2 oae users 4096 Jul 31 14:21 .\ndrwxr-x--x+ 9 oae root 4096 Jul 26 13:59 ..\n-rwx---r-x 1 oae users 90 Aug 3 11:22 hello.py\n-rwx---r-x 1 oae users 225 Aug 3 11:22 index.php\n'

但是应该是这样的;


    total 16K
    drwx---r-x  2 oae users 4.0K Jul 31 14:21 ./
    drwxr-x--x+ 9 oae root  4.0K Jul 26 13:59 ../
    -rwx---r-x  1 oae users   90 Aug  3 11:22 hello.py*
    -rwx---r-x  1 oae users  225 Aug  3 11:22 index.php*

\n 字符不应显示。我该如何解决?

最佳答案

这可以工作

$output=shell_exec('/usr/bin/python hello.py');
echo "<pre>";
print_r($output);
echo "</pre>";

关于php - 在 PHP 中正确打印 python 脚本输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792129/

相关文章:

php - 在 woocommerce 中过滤货币并将其从 usd 转换为 inr for ccavenue

python - 通过 D-Bus 获得有关剪贴板更改的通知

python - 填充检测到的 Blob (OpenCV,Python)

Php脚本从其他数据库更新VIEW

php - 在带有图像的 Telegram Bot 中发送消息

php - 拉维尔 4 : No hint path defined

python - Scrapy、Splash和连接被对方​​拒绝: 10061

python - 在不同情况下如何使用正则表达式修改 pandas 中的字符串

python - 加速索引 "revert"

php - PDO 和 MYSQL 的问题