Re: not working
SETLOCAL in TCC *does* support ENABLEDELAYEDEXPANSION (in batch files, not
from the command line). Can you post an example of what is failing for you?
Again, can you post an example?
Rex Conn
JP Software
Posted before in this thread:
http://www.jpsoft.com/forums/showpost.php?p=9449&postcount=7
the :rpath subroutine doesn't replace.
When it echo %rpath% it print !rpath:[...]\=! directly, such replacement works in CMD.
a simplified test case here:
Code:
@echo off
setlocal enabledelayedexpansion
for /R %%i in (.) do (
call :rpath %%~i
echo %rpath%
)
endlocal
GOTO :EOF
rem sub rpath(filename) OUT: %rpath%
:rpath
rem debug print %1 here
echo (rpath: %1)
SET rpath=%~1
set rpath=!rpath:%CD%\=!
GOTO :EOF
CMD result:
Code:
F:\app_related\TCCLE>rpath
(rpath: F:\app_related\TCCLE\.)
.
(rpath: F:\app_related\TCCLE\abd\.)
abd\.
(rpath: F:\app_related\TCCLE\dfe\.)
dfe\.
F:\app_related\TCCLE>
TCC result:
Code:
[F:\app_re~1\TCCLE]rpath
(rpath: F:\app_re~1\TCCLE\.)
!rpath:F:\app_re~1\TCCLE\=!
(rpath: F:\app_re~1\TCCLE\abd\.)
!rpath:F:\app_re~1\TCCLE\abd\=!
(rpath: F:\app_re~1\TCCLE\dfe\.)
!rpath:F:\app_re~1\TCCLE\dfe\=!
[F:\app_re~1\TCCLE]
and another type of delayed expansion fails. example from
http://ss64.com/nt/syntax-replace.html :
Code:
:: To remove characters from the right hand side of a string is
:: a two step process and requires the use of a CALL statement
:: e.g.
SET _test=The quick brown fox jumps over the lazy dog
:: To delete everything after the string 'brown'
:: first delete 'brown' and everything before it
SET _endbit=%_test:*brown=%
Echo We dont want: [%_endbit%]
::Now remove this from the original string
CALL SET _result=%%_test:%_endbit%=%%
echo %_result%
in CMD:
We dont want: [ fox jumps over the lazy dog]
The quick brown
in TCC:
We dont want: [ fox jumps over the lazy dog]
The quick brown fox jumps over the lazy dog: fox jumps over the lazy dog
TCC already supports all of those arguments (and DisableDelayedExpansion,
which CMD does not).
Note that TCC always supports delayed expansion (and always has), unless
it's explicitly disabled.
Rex Conn
JP Software
always enabling delayed expansion even on %var% might not be good on all scripts.
Quote from
http://blogs.msdn.com/oldnewthing/archive/2006/08/23/714650.aspx :
That's because the command interpreter expanded the environment variables at the time the line was read (not at the time the line is executed), yielding
set VAR=after & echo before
As a result, the old value of VAR is echoed. Some people treat this as a feature, allowing them to "restore" a variable without having to save it anywhere:
set VAR=newvalue & call helper.cmd & set VAR=%VAR%
a simple test case using this 'feature':
Code:
@echo off
set varx=abc
set varx=def& call :gsub & set varx=%varx%
:gsub
echo (gsub: %varx%)
in CMD:
(gsub: def)
(gsub: abc)
in TCC:
(gsub: def)
(gsub: def)
Also CMD style escape char fails in delayed variables (hellohtml.bat).
[ script content and results were pasted in pastebin.ca (
http://pastebin.ca/1868846 ) because forum kills html tags. ]