【发布时间】:2010-12-23 04:38:55
【问题描述】:
我用python调用ant,我想得到ant的返回码来检测ant错误。
例如,在 cmd.exe 中,
C:\Documents and Settings\Administrator>ant sfsf
Buildfile: build.xml does not exist!
Build failed
C:\Documents and Settings\Administrator>echo %ERRORLEVEL%
1
但是在python中:
>>> a = subprocess.Popen("ant hahah",shell=True)
>>> Buildfile: build.xml does not exist!
Build failed
>>> a.wait()
0
因为ant是bat文件,所以必须使用shell=True来调用Popen。 那么如何在 Python 中获取返回码(1)呢?
编辑:我发现使用“call ant ...”可以解决这个问题,感谢您的回答。
【问题讨论】:
标签: python ant subprocess