Squashman wrote:Read Jeb's explanation of how the cmd parser works.
Will not help here, as this part isn't expained there.
But this question is nearly the same (or better, the answer is the same)
Why does delayed expansion fail when inside a piped block of code?The behaviour looks very strang here, but if you know the cause it's obvoius
Both sides of a pipe are executed in a new cmd.exe context.
And both sides are executed like a command at the command prompt, that is important, as executing commands at the command prompt are handled different than commands in batch files.
(Ok at this point the parser explanation could be helpful).
Effectivly there are two phases in you examples.
The first phase is in the batch file, the
standard percent expansion rules.
Code: Select all
anyCmd | echo Test2 %%A%%
anyCmd | echo Test3 %%%%A%%%%
->
anyCmd | echo Test2 %A%
anyCmd | echo Test3 %%A%%
The next phase is the percent expansion at the command prompt in the new cmd.exe context.
And here the percent expansion works different, as in batch files.
Code: Select all
echo Test2 %A%
echo Test3 %%A%%
->
echo Test2 B
echo Test3 %B%
The expansion in test3 looks strange, but it's normal at the command prompt.
Hope it helps
jeb
PS: btw. what a luck for me, that Dave isn't online now, so I had the time to answer an interesting question