Python执行系统命令并获得输出的几种方法
参考博客:https://blog.csdn.net/dingyaguang117/article/details/7236296
Python执行系统命令并获得输出的几种方法
方法一:
import os
p = os.popen('uptime')
x=p.read()
print x
方法二:
import subprocess
res = subprocess.Popen('uptime',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
result = res.stdout.readlines()