26.08.2011 16:03:19 (8 years ago)

The flag --mode=gli has been introduced into LocalLibraryServer?.jar, and the prefix used in, while gs2-web-server.bat makes sure these are all passed to Server2, though gs2-web-server.bat no longer parses the cmdline args itself. This commit belongs with the the Server2 of commit r24491, where Server2's main method handles messy commandline arguments of the kind where parameters are split over multiple arguments, which can happen when gs2-webserver.bat calls Server2 now. The logic of dealing with spaces in filepath (and messy parameters) is therefore moved now from gs2-webserver.bat into

1 modified


  • main/trunk/greenstone2/gs2-web-server.bat

    r23987 r24492  
    191191:: GLI launches gs2-server.bat with: 
    192 :: cmd /c start "window" "c:\path to\gs2-server.bat" --config=c:\path to\glisite.cfg [--quit=portnum] 
     192:: cmd /c start "window" "c:\path to\gs2-web-server.bat" --config=c:\path to\glisite.cfg --quit=portnum --mode=gli 
     193:: where the --options are generally optional, but always used for GLI. 
    193194:: The configfile param could contain spaces, in which case its space-separated parts spread over  
    194 :: multiple parameters . Need to handle things the following way, since using quotes to embed the  
    195 :: parameters breaks the start command, see 
    196 :: This script is launched by the start cmd as: 
    197 :: "c:\path to\gs2-server.bat" --config=c:\path to\config.cfg [--quit=portnum].  
    198 :: But if the parameter  following --config=<some string> doesn't start with a double hyphen, we 
    199 :: assume it to be part of the config parameter, as the configfile path may have contained spaces. 
    201 :: Store all parameters together in config file var: we may or may not have a portnumber 
    202 :: Get everything after the "--quitport=", if anything, and store it in port var.  If no port, nothing to do. 
    203 set conf=%* 
    204 if "%conf%" == "" goto :runit 
    206 set port=%conf:*--quitport=% 
    207 if "%conf%" == "%port%" ( 
    208 set port= 
    209 goto :runit 
    210 ) else ( 
    211 set port=%port:~1% 
    212 ) 
    214 :: Because we got here, need to adjust conf by removing " --quitport=" from it and prefixing this to port 
    215 call set conf=%%conf:%port%=%% 
    216 set conf=%conf:~0,-12% 
    217 set port=--quitport=%port% 
    219 :: Remove trailing spaces from conf and port 
    220 :: (We'll put the all-important quotes around conf and port when the actual java cmd is launched) 
    221 set tmp=%conf% 
    222 call :trim %tmp% 
    223 set conf=%tmp% 
    224 set tmp=%port% 
    225 call :trim %port% 
    226 set port=%tmp% 
    227 set tmp= 
    229 goto :runit 
    231 :: 
    232 :trim 
    233 set tmp=%* 
    234 goto :eof 
     195:: multiple parameters. In the past, we used to handle this problem here.  
     196:: At present we pass all the arguments as-is to the Server.jar program and let it handle the parameters. 
     197:: E.g. gs2-web-server.bat --config=C:\pinky was\here at greenstone2\glisite.cfg --mode=gli --quitport=50100 
     198:: or gs2-web-server.bat --quitport=50100 --config=C:\pinky was\here at greenstone2\glisite.cfg --mode=gli 
     199:: Note the (lack of) use of quotes! 
    243209::echo port: %port%& echo conf: %conf%& echo.& echo. 
    244 :: "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" %* 
    245 "%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" "%conf%" "%port%" 
    248 :: The 1st argument to gs2-server.bat (if any) would be --config, the 2nd is the config filename.  
    249 :: Both are stored in %conf% now. If the config file is glisite.cfg, then this script was launched through 
    250 :: GLI and would have opened a DOS console. Need to exit from this script then to close the console. 
    251 :: Remove --config=prefix and do a case insensitive comparison, since filepaths can have uppercase chars 
    252 if "%conf%" == "" goto exit 
    253 if /i "%conf:~9%" == "%GSDLHOME%\glisite.cfg" goto quitcmd 
    254 goto exit 
     210:: Do not remove the quotes around %* !!! It's what helps Server2.jar deal with spaces in configfile path 
     211"%JAVA_EXECUTABLE%" org.greenstone.server.Server2 "%GSDLHOME%" "%serverlang%" "%*" 
     214:: All params are stored in %* now. This batch script can be called from the commandline or from GLI 
     215:: If the --mode(=gli) flag was passed in as parameter, then this script was launched through GLI 
     216:: and would have opened a DOS console. Need to then exit from this script to close the console. 
     217set allparams=%* 
     218:: And if there were absolutely no params to gs2-web-server.bat, it's not called from GLI either 
     219if "%allparams%" == "" goto exit 
     220set glimode=%allparams:--mode=% 
     221:: if one of the parameters was --mode(=gli), we close the console 
     222if /i "%allparams%" == "%glimode%" (  
     223    goto exit  
     224) else (  
     225    goto quitcmd  
    256228:: Exit the batch script (close the console)