2011-09-22 178 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`