python调用exe,希望高手指点。
如题,这个问题并不新鲜,但是我确实搞不明白了,这次。
一个exe程序,我在cmd下可以运行(运行时候不需要任何参数输入),找到exe路径,敲回车就行。正常输出结果。但是得等一会才会输出结果(输出一个txt文本),因为本身exe运行起来需要2分钟时间。
但是我在用python调用的时候就是没反应啊。我的代码这样:
exe_1=dstDir+'interpolation.exe' print exe_1 os.popen(exe_1)
[root@RHEL6B pycode]# ./py13.py not set: [root@RHEL6B pycode]# vim py13.py [root@RHEL6B pycode]# ./py13.py Success:this is test text.[root@RHEL6B pycode]# cat py13.py #!/usr/bin/env python#coding:utf-8from subprocess import Popen, PIPEreturn_code=-999 proc = Popen(['/root/shcode/sleep.sh'], stdout=PIPE, stderr=PIPE)return_code = proc.wait()voutput=proc.stdout.read()if return_code == 0: print "Success:\n%s" % voutput elif return_code == -999: print 'not set:', voutputelse: print "Failure %s:\n%s" % (return_code, voutput)[root@RHEL6B pycode]# cat /root/shcode/sleep.sh #!/bin/bashsleep 10echo this is test text.[root@RHEL6B pycode]#
[解决办法]
你system那句里的字串参数,\201会被转义,老实点一律用\\或者/吧。
[解决办法]