在 Python 中运行 bash 命令并在浏览器上显示


run bash command in python and display on browser

我有这个简单的python代码:

import os
#os.system ("bash -c 'ls /home/'")
script = "ls /home/user/"
os.system(script)

如何使用 PHP 显示输出?

不是使用 HTML,而是首先使用 PHP,您可以使用shell_exec从 python 脚本输出到 HTML,例如

<?php $output = shell_exec("python scriptName.py");
echo '<p>'.$output.'<p>'; ?>