转自: 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();