我使用python來調用ant,我想獲取ant的返回碼來檢測ant的錯誤。Python:獲取窗口中的螞蟻子進程的返回碼
例如,輸入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
由於螞蟻是一個bat文件,所以我必須使用shell =真致電POPEN。 那麼如何獲得Python中的返回碼(1)?
編輯:我發現使用「呼叫螞蟻...」將解決這個問題,感謝您的答案。