after downloaded scala 2.10.2 for windows, and run scala I met such error:
"错误: 找不到或无法加载主类 scala.tools.nsc.MainGenericRunner"
which means "error: can't find or load main class scala.tools.nsc.MainGenericRunner". So I check the
scala.bat for reasons, and I found such function:
:set_home set _BIN_DIR= for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi echo in set_home: %_BIN_DIR% set _SCALA_HOME=%_BIN_DIR%.. goto :eof
After this function the _SCALA_HOME become
D:\program files\scala\files\scala\bin\.., which is obviously wrong. Anyway, after setting _SCALA_HOME to be right path the error fixed. However, do any one knows what
%%~dpsi mean and what this function is really trying to do ? Thank you!
thank you @gourlaysama
I finally found the real reason：execute the following code and you can see the result is :
for %%i in (%~sf0) do ( echo "%%"i is: %%i echo sf0 is : %%~dpsi set _BIN_DIR=%_BIN_DIR%%%~dpsi )
"%"i is: D:\program sf0 is : D:\ "%"i is: files\scala\bin\scala.bat sf0 is : D:\program files\scala\bin\files\scala\bin\
so the malfunction is result from the extra space between
Those weird variables are called parameter extensions. they allow you to interpret a variable as a path to a file/directory and directly resolve things from that path.
For example, if
%1 is a path to a file
%~f1is the fully qualified path to
%~p1is the path to the containing directory
%~s1is the path in short name format
- and many others...
%0 is always set to the path of the currently running script. So:
%~fs0is the fully qualified path, in short name format, to the current script,
%%~dpsiis the manual expansion of the
%%ito a drive letter (
doption) followed by the path the containing folder (
poption), in short format (
Now, this weird looking block of code is a workaround for KB833431 in which the
%~dps0 command does not give you the path to the folder of the current script (in short format) although it should. This was fixed in XP SP2.
It seems to be reconstructing manually the fully qualified path to the scala
bin directory from the fully qualified path to
scala.bat, and then just getting that directory's parent, which should be a valid