试试这个:
import subprocess
# cmd contains shell command
cmd="your command shell"
process = subprocess.Popen(cmd,shell=True,stdin=None,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
# The output from your shell command
result=process.stdout.readlines()
if len(result) >= 1:
for line in result:
print(line.decode("utf-8"))