2011-09-22 144 views
1

我在Windows 7上使用在Cygwin上运行的bash shell。我在我的bash脚本中试图找出构建文件的位置基于当前执行脚本的位置...通过shell脚本运行ant时无法找到build.xml文件

SCRIPT_DIR="$(cd -P "$(dirname "$0")" && pwd)" 
BUILDFILE=$SCRIPT_DIR/build.xml 
ant -buildfile $BUILDFILE -Dbuildtarget=$1 -Dmodule="$2" -Dproject=$3 -Dnolabel=true -DFirefox=$4 -DInternetExplorer=$5 -DGoogleChrome=$6 Selenium4 

然而,即使该文件是存在的,我得到一个“无法找到构建文件错误”

$ sh c:/selenium//run_client_tests.sh prod "\Critical Path\Live\QX" MyProj true false false 
cygwin warning: 
    MS-DOS style path detected: c:/selenium//run_client_tests.sh 
    Preferred POSIX equivalent is: /cygdrive/c/selenium/run_client_tests.sh 
    CYGWIN environment variable option "nodosfilewarning" turns off this warning. 
    Consult the user's guide for more details about POSIX paths: 
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames 
Started script 
Buildfile: \cygdrive\c\selenium\build.xml does not exist! 
Build failed 

LS揭示文件是存在的......

[email protected]_w7 /cygdrive/c/selenium 
$ ls /cygdrive/c/selenium/build.xml 
/cygdrive/c/selenium/build.xml 

[email protected]_w7 /cygdrive/c/selenium 
$ ls c:/selenium/build.xml 
c:/selenium/build.xml 
+0

任何你与DOS'清盘机会\ r \ n'脚本文件中的结尾?我不记得,Cygwin是否善意地处理这件事?祝你好运。 – shellter

回答

2

这里的问题是,蚂蚁不知道Cygwin风格的路径。请注意,ant在抱怨找不到\ cygdrive \ c \ selenium \ build.xml。这是因为/ cygwin只能被Cygwin shell理解。

你需要做的是向DOS传递一个DOS风格的路径。所以更换

BUILDFILE=$SCRIPT_DIR/build.xml 

BUILDFILE=`cygpath -w $SCRIPT_DIR/build.xml` 

或者使这个多一点的平台无关的,使用Java风格的路径

BUILDFILE=`cygpath -m $SCRIPT_DIR/build.xml`