import subprocess ret = subprocess.Popen('netstat -ano',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) # PIPE管道 print(ret.stdout.read().decode('gbk')) # 需要解码 print(ret.stderr.read().decode('gbk')) # 需要解码
import subprocess ret = subprocess.Popen('netstat -ano',shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE) # PIPE管道 print(ret.stdout.read().decode('gbk')) # 需要解码 print(ret.stderr.read().decode('gbk')) # 需要解码