python 调用系统命令并获得标准输出,错误输出

转自: http://reader.youdao.com/sharelite?itemId=-447170961514257704&method=viewSharedItemThroughLink&sharedBy=-1137845767117085734 


import subprocess
cmd_res = {}
res = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True);
cmd_res['out']=res.stdout.readlines();
cmd_res['err']=res.stderr.readlines();

你可能感兴趣的:(python)