Python:Shell获取输出

问题

使用Python的subprocess模块调用外部可执行程序,然后需要用python获取可执行程序的输出

解决代码

#定义输出格式
p = subprocess.Popen(cmd_para,shell=True,stdout=subprocess.PIPE)
#获取所有的输出流
while p.poll() is None:
  #每次获取一行输出,并且将byte转换为utf-8格式
  print(p.stdout.readline().decode('utf-8')
p.wait()

猜你喜欢

转载自blog.csdn.net/u012348774/article/details/80140261