Reputation: 21
I am calling a shell script from ANT build.xml on a windows machine in which I have cygwin installed. The script is getting called and the initial echo statements are being executed in the script. But it is throwing error at statements like 'sed' or 'find' in the script. When I execute the script in cygwin directly it is successfully executed. On when it is called from ANT, it thows error and build fails. I am calling the shell script from build.xml as below:
<target name="xml2prop"
description="exec shell script"
>
<exec dir="." executable="C:\cygwin\bin\bash" osfamily="windows">
<arg value="C:\script\testscript.sh"/>
<arg value="${root}"/>
</exec>
</target>
The shell script snippet is as below:
if [ $# -lt 1 ]
then
echo "error"
else
echo "\$1 is \"$1\" and total args to $0 are $# "
rt="${1//\\//}"
echo $rt
fi;
find "$rt" -name "*.xml" |
while read xmlfile
do
echo "$xmlfile";
done
The error that I am getting is as below
[exec] $1 is "C:\new\test" and total args to C:\script\testscript.sh are 1
[exec] C:/new/test
[exec] FIND: Parameter format not correct
Can you please help me to figure out the problem?
Upvotes: 1
Views: 1082
Reputation: 18459
What is your path like? It looks like the script is actually running windows find.exe. In may be good idea to use absolute path to invoke commands
FIND_CMD=/bin/find
ANOTHER_COMMAND=/usr/bin/find
//assert find command exists
if [ ! -x $FIND_CMD ]
echo "not found command "
exit 1;
fi
if [ $# -lt 1 ]
then
echo "error"
else
echo "\$1 is \"$1\" and total args to $0 are $# "
rt="${1//\\//}"
echo $rt
fi;
$FIND_CMD "$rt" -name "*.xml" |
while read xmlfile
do
echo "$xmlfile";
done
In general avoid calling platform specific scripts from ant. Writing a java task or a program is far easier.
Upvotes: 1
Reputation: 15157
I think you are running the script in the Windows Shell not in Cygwin. In this case you'd be calling the FIND that comes with Windows and get the exact error you are reporting.
I'd look at how you are running your script and make sure that you are calling the proper Cygwin shell to run your script.
Upvotes: 0