Thanks Dave,
you get my points.
I'm sorry to choose a really bad example for
1) Why does delayed expansion fail when a batch executes (without CALL) another script?
I should have choose an example with a plain simple variable, not with a line feed
2) Why does CALL strip all content after the first newline?
Some strange behaviour, but I will open a new thread for that.
Examination of Linefeeds with CALL3) Transfering and accessing line feeds to another batch in a parameter
Aacini wrote:I think there is a confusion here...
If you read the SO question that jeb refers to in the first post of this thread, you'll realize that the problem stated there is create a disk file with three lines when such lines are stored in a multi-line variable and such value is passed in the parameter of a Batch file (executed via cmd /C batch.bat).
Yes, I'm still not sure, that I understand you.
But I added a working solution to bring a multi line variable into a parameter with a helper function (as I'm understand the problem of the OP was to receive the result not to get the multi line variable into the parameter).
And I added a simple parser
Code: Select all
@echo off
setlocal EnableExtensions DisableDelayedExpansion
prompt :
(
@echo on
for %%a in (4) do (
@goto :next
rem # %~1#
)
) > param.tmp
:next
@echo off
endlocal
setlocal DisableDelayedExpansion
set lineNo=0
(
for /F "skip=3 delims=" %%L in (param.tmp) do (
set /a lineNo+=1
set "line=%%L"
setlocal EnableDelayedExpansion
if !lineNo! EQU 1 (
set "line=!line:*# =!"
set "line=!line:~,-2!"
) ELSE IF "!line!"==") " (
goto :exit
) ELSE (
set "line=!line:* =!"
set "line=!line:~,-1!"
)
(echo(!line!)
endlocal
)
) > file.txt
:exit
type file.txt
But back again to my main issue:
Delayed expansion fails in some casesI made some more experiments
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "var=content"
echo.bat ---!var!---
bat ---content---
But when echo.bat exists
Then the delayed expansion fails
REM # ---!var!--- #
penpen wrote:I think i've read before that delayed Expansion "differs" between command and parameter string (although the consequences were different), but i cannot remember where;
if i had to guess, i would say it was a post/code from jeb/dbenham/both - something like this:
Yes, I described somewhere that the delayed expansion is completly independent for the command token and the remaining parameter tokens.
But your comment inspired me to test another case
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "var=content"
receiver.bat 1--!var!--
versus
set cmd=receiver.bat
!cmd! 2--!var!--
output wrote:REM # 1--!var!-- #
versus
REM # 2--content-- #
Strange
jeb