I suppose Rob think of things like this:
call :func | more
exit /b
:func
echo line1
echo line2
exit /b
Or something like
setlocal EnableDelayedExpansion
set var=Line2
( echo Line1
echo !var! ) | more
For this the explanation can be found at(you mentioned this)
SO:Why does delayed expansion fail when inside a piped block of code?
But redirection in the first step works with CALL
as expected (and the other characters)
call echo Hello > output.txt
But if you try to use any of the special characters in the second expansion of the CALL command, the complete command will not be executed.
About the special effects of CALL
for the batch parser is described at
SO:How does the CMD.EXE parse scripts? (especially phase 6)
set "myCmd=echo 1 & echo 2"
call %%myCmd%%
The double %%
have the effect that the first expansion results in %myCmd%
and the real expansion of the content will be done not until the second run of the parser, so the &
have to be interpreted in the call
context.
And also this will result in nothing (because of the parenthesis)
set "myCmd=echo Line1"
call (%%myCmd%%)
But this will obviously call a batch file named 1.bat
echo echo Hello > 1.bat
set "myCmd=echo Line1 && echo Line2"
call (%%myCmd%%)
echo End
This was discussed at dostips:CALL me, or better avoid call
Currently I suppose, CALL
works somehow with tokens, but can't handle them in the correct way.