我想在Cygwin下運行Rails,但是當我鍵入「rails -v」時,它找到「rails」並引發錯誤。當我輸入「rails.bat -v」時,它工作得很好。在原生Windows命令處理器中工作正常,因爲它使用PATHEXT來標識.BAT之類的可執行文件。如何配置Cygwin使用PATHEXT環境變量進行搜索?
我添加了一行到.bash_profile如下,它是設置變量,據我所知。
export PATHEXT=".RB;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
這是我的輸出:
$ echo $PATH
/usr/local/bin:/usr/bin:/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Program Files/WIDCOMM/Bluetooth Software:/cygdrive/c/Program Files/WIDCOMM/Bluetooth Software/syswow64:/cygdrive/c/Program Files (x86)/Windows Live/Shared:/cygdrive/c/Program Files/Intel/WiFi/bin:/cygdrive/c/Program Files/Common Files/Intel/WirelessCommon:/cygdrive/c/Program Files/Microsoft Windows Performance Toolkit:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Microsoft/Web Platform Installer:/cygdrive/c/Program Files/7-Zip:/cygdrive/d/sysinternals:/cygdrive/d/batch:/cygdrive/d/Program Files/Sublime Text 2:/cygdrive/d/RailsInstaller/Ruby1.9.3/bin:/cygdrive/d/RailsInstaller/Git/cmd:/cygdrive/d/RailsInstaller/Git/bin:/usr/bin:/cygdrive/d/batch
18:54~
$ echo $PATHEXT
.RB;.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
18:54~
$ which rails
/cygdrive/d/RailsInstaller/Ruby1.9.3/bin/rails
18:54~
$ which rails.bat
/cygdrive/d/RailsInstaller/Ruby1.9.3/bin/rails.bat
18:55~
$ rails -v
D:\RailsInstaller\Ruby1.9.3\bin\ruby.exe: No such file or directory -- /cygdrive/d/RailsInstaller/Ruby1.9.3/bin/rails (LoadError)
18:55~
$ rails.bat -v
Rails 3.2.11
18:55~
$
我嘗試使用您引用的鏈接中提供的第二個答案,而不是第一個和接受的答案。它使用別名命令將rails轉換爲rails.bat。它似乎在工作,但我會尋找副作用。儘管如此,我將不得不考慮完全原生。 –