I've also done a bunch of tests with some annotation in the code. It will be hard to read unless you copy the code into your own text editor.
Some of the tests aren't so much about token dropping, but rather demonstrate some of the rules in my earlier post.
But the majority investigate token dropping. The analogs to your recent tests begin at #14.
It is odd how the parser seems to have a hard time deciding if the subsequent redirection is escaped or not.
Unfortunately my test #10 disproves my theory that the token dropping is due to the redirection parser blindly parsing the next token - that token dropping requires 2 tokens after the redirection token
Code: Select all
@echo off :: Handle line continuation with fatal syntax error without crashing out if "%~1" neq "" ( echo on call :%1 exit /b %= exit really shouldn't be needed =% ) setlocal prompt $G echo on cls :: Basic token dropping ceases after token delimiter found after next token echo #1 Hello >con abc^ xyz^ 123^ world! ^ Nice^ to see you. :: Basic token dropping - next token does not have to start on first line echo #2 Hello >con ^ xyz^ world! Nice^ to see you. :: Token dropping continuation does not escape next character echo #3 Hello >con abc^ &echo world :: Redirection token must be complete before token dropping begins echo #4 Hello >^ c^ o^ n ^ abc^ world! :: Next token begins immediately after &n, no delimiter needed :( :: Beyond that, "normal" token dropping. echo #5 Hello >&2abc ^ 123^ world! :: No token dropping here because we already have token delim after next token echo #6 Hello >&2world! ^ Nice to see you. :: &n does not work with token delimiter in front cmd /c "echo #7 Hello > &2 world" :: ^&n works, subsequent characters in same token ignored, but in ECHO output echo #8 Hello> ^&2abc world :: Doesn't need to be a new token for ^&n to ignore subsequent chars echo #9 Hello>^&2abc world :: Thankfully this fails cmd /c "echo #10 Hello >&bad world" :: Damn! This still has token dropping :( :: So not as simple as parser blindly grabbing next token. :: Rather parser wants next token after destination found. :: WHY? echo #11 Hello > ^&2 abc^ world :: Still "normal" token dropping echo #12 Hello >con abc^ <nul abc^ world :: No token actually dropped with this line continuation before finding :: a token after the redirection, but the token drop behavior of not escaping :: the next character is still in play echo #13 Hello >con ^ &echo world cmd /c "%~f0" :14 & goto :skip :14 :: This is the beginning of total weirdness. Same as 13 except substitute :: redirection for concatenation. But now the original redirection is lost :: and the next token is used, with the 2nd redirection escaped! HUH? echo #14 Hello world >dropped ^ <nul :skip :: Same as test 14, except add a 2nd token on the continued line. :: Now the 1st destination returns, the 2nd redirection is no longer :: escaped, but the destination in that token is ignored, and the next :: token is used instead. WTF! echo #15 Hello world >con ^ <dropped nul :: The whacky destination substitution can be continued onto the next line echo #16 Hello>con ^ <dropped ^ nul world :: Surprising how many token delimiters are dropped from the output echo #17 Hello>con ^ <dropped nul ^ world :: Escaped token delimiter can be part of destination echo #18 Hello>con ^ <dropped nul^ destinationContinued world :: Same as 18 except ^&n still not bothered by extra chars echo #19 Hello>con 4<nul ^ <dropped ^&4^ destinationContinued world :: No difference between input vs output echo #20 Hello 4>nul ^ >dropped con ^ world
Code: Select all
>echo #1 Hello world! Nice to see you. 1>con #1 Hello world! Nice to see you. >echo #2 Hello world! Nice to see you. 1>con #2 Hello world! Nice to see you. >echo #3 Hello 1>con & echo world #3 Hello world >echo #4 Hello world! 1>con #4 Hello world! >echo #5 Hello abc 123world! 1>&2 #5 Hello abc 123world! >echo #6 Hello world! Nice to see you. 1>&2 #6 Hello world! Nice to see you. >cmd /c "echo #7 Hello > &2 world" & was unexpected at this time. >echo #8 Hello world 1>&2abc #8 Hello world >echo #9 Hello world 1>&2abc #9 Hello world >cmd /c "echo #10 Hello >&bad world" >& was unexpected at this time. >echo #11 Hello world 1>&2 #11 Hello world >echo #12 Hello world 1>con 0<nul #12 Hello world >echo #13 Hello 1>con & echo world #13 Hello world >cmd /c "C:\test\test.bat" :14 & goto :skip The syntax of the command is incorrect. ><nul >echo #15 Hello world 1>con 0<nul #15 Hello world >echo #16 Hello world 1>con 0<nul #16 Hello world >echo #17 Hello world 1>con 0<nul #17 Hello world >echo #18 Hello world 1>con 0<nul destinationContinued The system cannot find the file specified. >echo #19 Hello world 1>con 4<nul 0<&4 destinationContinued #19 Hello world >echo #20 Hello world 4>nul 1>con #20 Hello world