2010-10-20 59 views
1

我知道我們可以這樣調用:如何在python腳本中調用ant任務?

os.system("ant compile") 

但如何知道螞蟻任務是否成功?

是否有另一種方式來調用ant任務?

+0

可能http://stackoverflow.com/questions/1846025/python-get-the-return-code-of-ant-sub-process-in-windows的副本 – 2010-10-20 04:57:09

回答

0

你可以修改ant來返回一個成功的代碼,並捕獲它在python中的返回?

http://www.dotkam.com/2008/10/24/getting-return-code-from-ant-in-shell/

+1

這是一個很好的和有益的文章,但我想從python腳本中獲取返回碼,而不是SHELL – user481255 2010-10-20 08:36:21

+1

將其返回到Shell,然後將其轉換爲python:http://pydanny.blogspot.com/2007/11/capturing-shell-output -in-python.html – Erik 2010-10-21 22:08:42

0
import subprocess 
p1 = subprocess.Popen('ant compile', stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) 
print p1.stdout.read(-1) 
print p1.stdin.read(-1) 
print p1.stderr.read(-1) 

嘗試使用子得到的輸出/錯誤.....

+0

非常感謝! – user481255 2010-10-20 08:34:39

1

os.system返回一個返回代碼。所以你可以抓住它並檢查它。

rc = os.system("ant compile") 
if rc != 0: 
    print "Error on ant compile" 
    sys.exit(1) 
相關問題