2010-10-20 47 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)