【发布时间】:2019-05-19 10:37:39
【问题描述】:
我想在 python 中打印一个 Pi 的操作系统系统信息。 操作系统命令“cat /etc/os-release”在终端中运行良好,行格式很好。
在 Python 中我使用了:
import subprocess
output = subprocess.check_output("cat /etc/os-release", shell=True)
print("Version info: ",output)
这行得通,但我没有得到任何换行符:
Version info: b'PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"\nNAME="Raspbian GNU/Linux"\nVERSION_ID="9"\nVERSION="9 (stretch)"\nID=raspbian\nID_LIKE=debian\nHOME_URL="http://www.raspbian.org/"\nSUPPORT_URL="http://www.raspbian.org/RaspbianForums"\nBUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"\n'
如何格式化输出以添加换行符?
【问题讨论】:
-
'str(output)' 可以工作
标签: python linux subprocess