Hi Dave,
dbenham wrote:I know from prior posts that there is special FOR parsing in phase 2 and it is preventing code like the following from working.
dbenham wrote:Does anyone (jeb
) have a solution to this problem
I'm not very optimistic, but you have surprised me in the past jeb.
Sorry
, this time I didn't see any way other than using a CALL or nested FOR, as you said the main problem is the parsing phase of the FOR-parameters.
Even with a %%var you can't bypass the problem, as the FOR-parameters are fixed before execution.
Code: Select all
setlocal enableDelayedExpansion
(
set "str= "
FOR %%D in ("!str!") DO (
for /f "EOL=%%~D tokens=* delims=%%~D" %%a in (" Hello world") do echo %%a
)
)
The nested FOR would work, but I suppose it's speed is less or equal to CALL, and it's not so flexible like a CALL.
The CALL-variant can access and change the normal variables and also access the other FOR-variables, both fails with the nested-FOR variant.
Code: Select all
@echo off
setlocal enableDelayedExpansion
set "cmd=for /f "EOL=%%str%% tokens=* delims=%%str%%" %%a in (" Hello world") do @echo %%a"
set cmd
(
set "str= "
for /F "delims=" %%x in ('!cmd!') do echo %%x
)
As I didn't know any way to "reparse" a FOR or IF in a block, I suppose there aren't better ways to solve it.
jeb