当前位置:编程学习 > 网站相关 >>

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

作者 小兔齐齐
补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,