2012-10-08 57 views
1

我在安装了cygwin的Windows机器上从ANT build.xml调用shell脚本。该脚本正在调用,并且脚本中正在执行初始回声语句。但它会在脚本中的'sed'或'find'等语句中引发错误。当我直接在cygwin中执行脚本时,它已成功执行。在从ANT调用它时,会出现错误并且构建失败。我打电话从build.xml中的shell脚本如下:当通过ANT调用shell命令时无法识别

<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> 

shell脚本片段是如下:

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 

,我得到的错误是如下

[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 

你能帮我弄清楚这个问题吗?

+1

为什么不作为字符串来回应find命令并查看传递给它的内容。 –

+0

某些旧版本的'find'没有默认'-print',你可以试试。如果没有,请在脚本的开头放置'set -x'来查看生成的值。 – cdarke

回答

0

我认为你在Windows Shell中运行的脚本不在Cygwin中。在这种情况下,您将调用Windows附带的FIND并获取您报告的确切错误。

我会看你如何运行你的脚本,并确保你正在调用合适的Cygwin shell来运行你的脚本。

+0

可以请你帮我弄清楚,如果以下是从Windows机器上的build.xml调用cygwin shell来运行shell脚本的正确方法吗?

+0

'重新调用它是正确的。然而,正如Jayan指出的那样,您需要确保您的PATH具有Cygwin工具,或者您在脚本中使用绝对路径。 – AlG

1

你的路径是什么样的?它看起来像脚本实际上运行Windows find.exe。在可能是使用绝对路径调用命令

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 

一般避免调用从蚂蚁平台特定的脚本好主意。编写一个java任务或一个程序要容易得多。

+0

感谢Jayan ..我的大多数命令都使用它在我的shell脚本中使用“jar”命令正在执行中创建一个问题。我应该为此做些什么? –