demeter
demeter copied to clipboard
Paths in Windows batch scripts should be improved
I think that #9, #16, and recent discussions on the ifeffit mailing list:
http://millenia.cars.aps.anl.gov/pipermail/ifeffit/2015-August/012663.html http://millenia.cars.aps.anl.gov/pipermail/ifeffit/2015-July/012588.html
are all related.
I suggest that the batch files begin like this
@rem = '--*-Perl-*--
@echo off
PATH=C:\Windows\system32;C:\Windows;C:\Windows\system32\Wbem
PATH=%PATH%;%~dp0;%~dp0\..\..\bin;%~dp0\..\..\..\c\bin
SET DOTDIR="%APPDATA%\demeter"
IF NOT EXIST %DOTDIR% MD %DOTDIR%
if "%OS%" == "Windows_NT" goto WinNT
perl.exe -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 > "%APPDATA%\demeter\%~n0.log" 2>&1
goto endofperl
:WinNT
perl.exe -x -S %0 %* > "%APPDATA%\demeter\%~n0.log" 2>&1
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!perl.exe
#line 17
BEGIN {
....
That is:
- explicitly set PATH.
- use %~dp0 to expand "the drive letter and path of the current file".
- use %~n0 to expand "the pre-dot portion of the current file, after path", that is 'dathena' for dathena.bat. This makes this paragraph static, and identical for all scripts.
I'm not sure why the
#!perl.exe
line is needed. It seems to not really matter what it points to.
I believe this will make the entire Demeter tree relocatable after installation (though shortcuts in the start menu would need to be updated). If this does work, the default install location could (and probably should) be changed to the user's APPDATA folder, so that admin privileges are not needed for installation.