Caml Light Posted November 8, 2011 Share Posted November 8, 2011 (edited) Hi guys, sorry for the stupid question, but i've a doubt about the use of quotes, so i would need to know if in a batch file is more correct to use:START /WAIT Updates\"%%~nA"\KB123456.exe /quiet or START /WAIT "Updates\%%~nA\KB123456.exe" /quietRD /S /Q Updates\"%%~nA" or RD /S /Q "Updates\%%~nA"RD /S /Q %Temp%\Dir or RD /S /Q "%Temp%\Dir" or RD /S /Q "%Temp%"\DirThank you in advance guys, you're always very helpful! Edited November 8, 2011 by Caml Light Link to comment Share on other sites More sharing options...
Ponch Posted November 8, 2011 Share Posted November 8, 2011 You only need quotes when there is a space in a file name or path name so the command knows it is not an other argument or switch. And if you use them, they should englobe the total name and path. So in your 2 first examples, 2nd part is correct. In the 3rd line, 1st part is best, 2nd is ok, 3rd is not (not sure it could work).But quotes are not needed in any as you don't have any spaces in names. Link to comment Share on other sites More sharing options...
Caml Light Posted November 8, 2011 Author Share Posted November 8, 2011 Thank you, now i've more clear ideas! Only in the last case, if %Temp% variable is: C:\Users\Name Surname\AppData\Local\Temp ... as you see there is a space, so is it correct to write "%Temp%"?Thanks!!!! Link to comment Share on other sites More sharing options...
Tripredacus Posted November 8, 2011 Share Posted November 8, 2011 No I think it is safe to use environment variables without quotes. Link to comment Share on other sites More sharing options...
allen2 Posted November 8, 2011 Share Posted November 8, 2011 Variable with space might be used without quote in some and never in other:- when using a variable with space after echo, you don't need quote whatever the variable with space (of course if the variable doesn't contain other special characters).- when using a variable with space after if (for testing), in most cases you'll need to have it quoted the only exception is the syntax "if defined". Link to comment Share on other sites More sharing options...
Caml Light Posted November 8, 2011 Author Share Posted November 8, 2011 ok guys, but Yzöwl wrote this:@ECHO OFF SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION FOR /R "%~dp0" %%A IN (*-KB*.EXE) DO ( CALL :SUB %%~nA ECHO= Installing KB!KB_NUM! >NUL PING -n 4 127.0.0.1 "%%A" /quiet /norestart) ECHO= == Press any key to restart == >NUL PAUSE SHUTDOWN.EXE /r /t 0 GOTO :EOF :SUB SET "KB_NUM=%*" FOR /F "DELIMS=-" %%B IN ("%KB_NUM:*-KB=%") DO SET "KB_NUM=%%B"as you can see, this variable has quotes: "%%A" /quiet /norestartSo, Tripredacus has written that it is safe to use environment variables without quotes. Could you explain me bacause in the batch i posted there are quotes? Sorry but i'm trying to understand better. Link to comment Share on other sites More sharing options...
allen2 Posted November 9, 2011 Share Posted November 9, 2011 Yzöwl was right: in this case if the hotfixes contains space in their name, the quotes are required (and won't cause any trouble). And that's why he put them. Link to comment Share on other sites More sharing options...
Caml Light Posted November 9, 2011 Author Share Posted November 9, 2011 (edited) ok, so summarizing, if i have an environment variable that contain spaces (ex. %COMMONPROGRAMFILES%\filename.exe -> C:\Program Files\Common Files\filename.exe), if i write in the batch:START /WAIT %COMMONPROGRAMFILES%\filename.exe i can use or less quotes, while writing:START /WAIT "C:\Program Files\Common Files\filename.exe" i MUST use quotesIs it correct??But simplifyng, for not commit errors can i always use quotes, also if not required because there aren't spaces (ONLY to start a program or delete file and folders with DEL/RD)?RD /S /Q "%Temp%\Dir"RD /S /Q "Updates\%%~nA"START /WAIT "Updates\%%~nA\KB123456.exe" /quietPS: for a simple question i'm making a dust cloud (sorry) Edited November 9, 2011 by Caml Light Link to comment Share on other sites More sharing options...
allen2 Posted November 9, 2011 Share Posted November 9, 2011 Yes and yes if you do it properly. Link to comment Share on other sites More sharing options...
jaclaz Posted November 9, 2011 Share Posted November 9, 2011 IMHO the issue is that you are failing to see some of the possibilities.If you have a variable Temp which value %Temp% resolves to (say) "C:\windows\my stupid path with spaces in it" (i.e. the quotes are INSIDE the value of the variable, when you "mix" them and enclose in quote you do a mess, i.e.:"%Temp%\my_folder" will resolve to ""C:\windows\my stupid path with spaces in it"\my_folder"which is NOT what you want.You want to have everything in quotes AND strip those quotes AND re-apply them "outside".Example:@echo offSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET partial_path="C:\my partial path with spaces"SET second_part="my dir_name also with spaces"SET partialSET secondCALL :strip partial_pathCALL :strip second_partSET partialSET secondCALL :join Full_path partial_path second_partSET FullGOTO :EOF:stripSET %1=!%1:"=!GOTO :EOF:joinSET %1="!%2!\!%3!"GOTO :EOFjaclaz Link to comment Share on other sites More sharing options...
Caml Light Posted November 10, 2011 Author Share Posted November 10, 2011 (edited) This is my batch:@ECHO OFFCOLOR F9ECHO=_%~1|FINDSTR/X "_-? _/?">NUL 2>&1||GOTO ErrorSETLOCAL ENABLEEXTENSIONSSET "_="PUSHD %~dp0FOR /R %%A IN (Windows*-KB*.EXE) DO ( SET _=T ECHO=Installation of %%~nA...>>install.log >NUL PING -n 4 127.0.0.1 "%%A" /quiet /norestart DEL /F /Q "%%A")IF NOT DEFINED _ GOTO Error:: ECHO=>>install.logECHO=Installation complete.>>install.log>NUL PING -n 4 127.0.0.1EXITGOTO :EOF:ErrorECHO=Errore di inizializzazione.>>install.log>NUL PAUSEMy doubts are about the quotes use for commands like: START /WAIT filename and DEL/RD file/folder. Instead of: "%%A" /quiet /norestart DEL /F /Q "%%A")i could have: START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q Dir\"%%~nA")where %%~nA is a subdirectory called with the name of the extracted file, or yet: START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q "%Temp%\Dir")So, i would need to adjust these double quotes for these typical cases to don't fall in error. Edited November 10, 2011 by Caml Light Link to comment Share on other sites More sharing options...
jaclaz Posted November 10, 2011 Share Posted November 10, 2011 My doubts are about the quotes use for commands like: START /WAIT filename and DEL/RD file/folder. Instead of: "%%A" /quiet /norestart DEL /F /Q "%%A")i could have: START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q Dir\"%%~nA")where %%~nA is a subdirectory called with the name of the extracted file, or yet: START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q "%Temp%\Dir")So, i would need to adjust these double quotes for these typical cases to don't fall in error.But you have to make up your mind, first:Is the batch to be run in the SAME directory where the "Windows*-KB*.EXE" (I presume Windows XP updates are saved?WHAT exact parameter are you supplying the batch as %1? ( a full path, a relative path, what)?Still IMHO running a bunch of updates with the /norestart parameter and in an order given by the result of the FOR /R loop may need LOTS of testing to make sure the thing actually runs.You have THREE options (two of which are "wrong", though for different reasons): "%%A" /quiet /norestart DEL /F /Q "%%A")this is not normally a good idea IMHO, using START /WAIT is always advised START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q Dir\"%%~nA")this one is seemingly OK, though the "Dir" materializes itself from thin air and you seemingly completely missed that the Quotes have to be BEFORE and AFTER START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q "%Temp%\Dir")this one is "wrong" for TWO reasons:you run a file in sub-directory of "Dir" (still materializing from thin air) that has the same name of the .exe file you should be running, BUT you have hardcoded the actual .exe file name then you delete EACH TIME the WHOLE contents of "%Temp%\Dir" (which is NOT the same "Dir" you used before).You quoted a snippet posted by Yzöwl here:AND changed it. WHY? (I mean see earlier what is the directory structure and placement of the batch you expect/want?)Have you tried using it EXACTLY as it was posted before anything else?In what that EXACT, AS IS, snippet does not work for you or what missing feature you want to add to it? (apart from the logging, I mean) jaclaz Link to comment Share on other sites More sharing options...
allen2 Posted November 10, 2011 Share Posted November 10, 2011 The right syntax for "start" is at least to give a title and an executable.START /WAIT Dir\"%%~nA"\KB123456.exe /quiet /norestart should be START "hotfix" /WAIT "Dir\%%~nA\KB123456.exe" /quiet /norestart and i put "hotfix" you can put almost whatever you want. I also set the right quoting method in this case.Lastly, i don't understand why you would get a folder named like Windows*-KB* (that's what you do when using "\%%~nA\ ") as in the batch you pasted, all hotfixes must be in the same folder.... Link to comment Share on other sites More sharing options...
Caml Light Posted November 10, 2011 Author Share Posted November 10, 2011 ok guys, Yzowl has modified his original batch, as you can see here: http://www.msfn.org/board/topic/153204-cmd-option-to-jump/page__st__20- updates are in the same directory (or in a sub-dir) of the file batch- sometimes, before to install an update, i have to extract a zip file (containing the update) in a Temp directory with 7-zip command line, for ex.:FOR /R %%A IN (filename*.ZIP) DO ( SET _=T ECHO=Extraction of %%~nA...>>install.log >NUL PING -n 4 127.0.0.1 Tools\7z x "%%A" -oDir\Temp\"%%~nA" -y ECHO=Installation of %%~nA...>>install.log >NUL PING -n 4 127.0.0.1 START /WAIT Dir\Temp\"%%~nA"\KB123456.exe /quiet /norestart RD /S /Q Dir\Temp\"%%~nA")This is my folder structure:- batch file- Tools ( dir that contains 7-Zip command line)- Dir and Temp (dir and subdir that contain updates and extracted updates)I hope you have explained better the situation. Thanks Link to comment Share on other sites More sharing options...
jaclaz Posted November 10, 2011 Share Posted November 10, 2011 This is my folder structure:- batch file- Tools ( dir that contains 7-Zip command line)- Dir and Temp (dir and subdir that contain updates and extracted updates)I hope you have explained better the situation. ThanksMUCH better than before , but not yet enough. Let's do it like this , prepare on a drive your source files EXACTLY as you wish to use them, let's say they are in a directory under root like "C:\teststructure" (containing directly or inside subdirectories a sample of the files you wish to use), then run:DIR /S C:\teststructure>C:\mystructure.txtzip the resulting C:\mystructure.txt and attach the zipped file.jaclaz Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now