我有一个 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/