Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANT doesn't get exit code return by a python script

I'm currently using ant for building my java project on a Windows XP machine. I have different tasks defined in the build.xml and one of this is the exec of a Python script for analyzing the application output. I would like to make ANT failing when a particolar tag is discovered by script. I'm trying using:

sys.exit(1)

or

os.system("EXIT 1")

the second one in particular execute the console command EXIT which successfully make the building process failing if executed inside a bath file.Unfortunately ant is not able to reveal the exit code from inside the launched script and goes on normally till the end showing a BUILD SUCCESSFUL message.

the script is called in this way:

<exec dir="${path}/scripts" executable="python">
        <arg line='log_analysis.py results.log" ' />
    </exec>

thanks for your help

like image 266
Claus Avatar asked Jun 09 '10 08:06

Claus


People also ask

How do I return an exit code in Python?

You can set an exit code for a process via sys. exit() and retrieve the exit code via the exitcode attribute on the multiprocessing.

How do I run an Ant script from the command line?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is the status code for a Python program indicating normal program exit?

The function calls exit(0) and exit(1) are used to reveal the status of the termination of a Python program. The call exit(0) indicates successful execution of a program whereas exit(1) indicates some issue/error occurred while executing a program.


1 Answers

Try this:

<exec dir="${path}/scripts" executable="python" failonerror="true">
    <arg line="log_analysis.py results.log" />
</exec>

Ant does not stop the build process if the command exits with a return code signaling failure by default; you have to set failonerror="true" to do that.

like image 151
Tamás Avatar answered Sep 24 '22 02:09

Tamás