Guys, you might come across some situations where you need to invoke shell and execute a bash script while building a project using Apache Ant. In today's example let's see how to run a shell script from within an Ant build.
For illustration, lets create a simple bash script to list the disk usage of our system. Let's name this file as "DiskUsage.sh"
Now let's create a simple build-test.xml using the exec command to invoke the shell as follows :
Run the ant build from command line as ant -f build-test.xml. Note that the shell script and build.xml happen to be at the same location/hierarchy within the project. If your shell script lies elsewhere, you may perhaps want to refer to its path in the build.properties instead.
You could also invoke the "expect" scripting prompt in a similar fashion to execute an expect script that we discussed in our earlier post.
More information on the exec can be read at the official Ant manual.
For illustration, lets create a simple bash script to list the disk usage of our system. Let's name this file as "DiskUsage.sh"
#!/bin/bash
# Sample shell script to be invoked from an Ant build
echo "Disk usage is as follows : \n"
echo "=========================== \n"
df -h
Now let's create a simple build-test.xml using the exec command to invoke the shell as follows :
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntBuildTest" default="call-shell" basedir=".">
<target name="call-shell">
<exec executable="/bin/bash">
<arg value="DiskUsage.sh"/>
</exec>
</target>
</project>
Run the ant build from command line as ant -f build-test.xml. Note that the shell script and build.xml happen to be at the same location/hierarchy within the project. If your shell script lies elsewhere, you may perhaps want to refer to its path in the build.properties instead.
You could also invoke the "expect" scripting prompt in a similar fashion to execute an expect script that we discussed in our earlier post.
More information on the exec can be read at the official Ant manual.
No comments:
Post a Comment