Skip to content Skip to sidebar Skip to footer

Python: Get The Return Code Of Ant Sub-process In Windows

I use python to call ant, I want to get the return code of the ant for detect ant error. for example, in cmd.exe, C:\Documents and Settings\Administrator>ant sfsf Buildfile: bu

Solution 1:

My idea to solve this: Get some regex on the output stream. If typical Keywords occur like "Error" you will be informed.

Solution 2:

As of this post it is recommended that the subprocess module be used to call applications, so for example:

#Change to the correct project directory (with your build.xml)
os.chdir(project_dir)
print(os.path.abspath(os.curdir))
#debug is your ant task, Get the return code, (note shell=True can be a large security risk)
output_return_code=subprocess.call(["ant","debug"],shell=True)

#or to caputure the output
output_text=subprocess.check_output(["ant","debug"],shell=True)
print(str(output_text,"utf-8").strip())

Python Version: 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit (AMD64)] Windows Version: Windows 7

Post a Comment for "Python: Get The Return Code Of Ant Sub-process In Windows"