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()





你可能感兴趣的:(shell,python,import)