Python调用exe程序得到输出的方法:
mmcmd = ' '.join(['MMxnyn', infile, str(kneig)])
方案一:
import commands
status, output = commands.getstatusoutput(micmd)
mi = output
方案二:
import subprocess
res = subprocess.Popen(micmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
mi = res.stdout.readlines()
mi = float((mi[0].strip()))
注:这里只用到了可执行程序输出的第一行,并转成float型返回。
方案三:
import os
p = os.popen(' '.join(['MIxnyn', zwspfile, str(Ndx), str(Ndy), str(N), str(kneig)]))
mi = p.read()
mi = mi.strip()
原文出处:http://www.conxz.net/blog/2013/10/25/sloppy-python-snippets-to-capture-command-output/