batch file - Some confusion in the call command documentation of the Windows XP command processor -


the reference @ ss64.com mentions call command can call internal command whereas windows xp command reference doesn't mention all. old ms dos command reference doesn't mention it. reason why found syntax confusing :

call set x= %x% elegant way of expanding user input environment variable compared using parsing capability of command expanded value of environment variable. why command processor have read input variable twice expand ? if user input entered directly command using works without problem. eg. "%userprofile%\desktop\file.txt" no brainer processor when typed directly when same string input via prompt system lost. when input variable has no spaces or special characters there's no need call it,it can used directly.

your confusion comes fact call set x=%x% replacement of set x=!%x%!, not of for feature. purpose expand variable value twice. simple example:

set /p "str=enter string: " set /p "start=enter start char: " set /p "len=enter number of chars: "  echo substring is: "!str:~%start%,%len%!"  call echo substring is: "%%str:~%start%,%len%%%" 

its easy realize there no way substring defined variables without expand value 2 times: 1 start/len values , 1 substring itself.

the same happen path: if value read include %variable%, there no way full path without expanding twice!

the key here these values comes user input, different put in batch file or enter in command prompt.

edit: example; execute command prompt:

c:\> set var=  c:\> set command=echo %var%  c:\> echo %command% echo %var%  c:\> %command% %var%  c:\> set var=this var value  c:\> %command% %var%  c:\> call %command% var value 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -