Jump to content

Help make CMD install on XP x86 only


Recommended Posts

But it should make a difference, jaclaz. Using % instead of ! gives only the initial value for the variable, not the most recent one. ;)

Edited by 5eraph
Link to comment
Share on other sites


But it should make a difference, jaclaz. Using % instead of ! gives only the initial value for the variable, not the most recent one. ;)

You would be correct 5eraph, if the variable usage had been inside a FOR loop, but not if it is just consecutive statements, unless I'm not understanding what you mean. In other words:

@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONSET "_OSV=1"SET "_OSV=2"SET "_OSV=3"SET "_OSV=4"SET "_OSV=5"SET "_OSV=6"SET "_OSV=7"SET "_OSV=8"SET "_OSV=9"SET "_OSV=0"SET "_OSV=" & FOR /f "TOKENS=2 DELIMS=[]" %%A IN ('VER') DO FOR /f "TOKENS=2,3 DELIMS=. " %%B IN ("%%~A") DO SET "_OSV=%%B.%%C"ECHO= _OSV=%_OSV%ECHO= _OSV=!_OSV!

will output two lines of the same thing -- _OSV=5.1 (or whatever the value is for your OS)

Cheers and Regards

Link to comment
Share on other sites

@5eraph, I absolutely love ss64.com, and robvanderwoude.com as well, for batch reference, but you probably misinterpreted the two special case examples given the first thing on your ss64 source page.
 
I might not be wording this completely right, but I'll try.  The key to remember is that without delayed expansion enabled, and/or variables using %, each batch statement is parsed and evaluated in its entirety with the value of the % variables as they were just before the statement was executed.  In the first example:

Set _var=firstSet _var=second& Echo %_var% !_var!

The second line, and any other time that multiple statements are connected with & or || or &&, is considered to be ONE batch statement which is why %_var% and !_var! will have different values when delayed expansion is enabled.  As jaclaz said, ' with delayed expansion on and ! you get the "current" value, whilst with % you get the value it had "before" '. The same is true with a FOR loop, or IF THEN, or any other collection of statements enclosed in parentheses, regardless if it is multi-line or all on one line. That is one batch statement, no matter how many lines are involved, that is parsed completely before it is executed.

The second example is even trickier, but it basically is a way of escaping a redirection, and other characters that would normally "screw up" a batch command by trying to cause an action, to be able to use batch to work with HTML and XML statements.
 
You can find another explanation of EnableDelayedExpansion here - http://blogs.msdn.com/b/oldnewthing/archive/2006/08/23/714650.aspx

Hope that helps.

Cheers and Regards

Edited by bphlpt
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...