in reply to Re: Re: Re: Windows command line
in thread Windows command line

If you can discern a pattern in that lot, I've several hundred more weird examples for analysis:)

Well, Im not going to claim that I fully grok whats going on. I doubt if even Microsoft will do that. But I do have some ideas.

It seems that the parser has at least four modes. Unquoted text, quoted text, and semi quoted seperable text, and semi quoted inseparable text. Semi quoted seperable text appears to be like quoted except that spaces are signifigant and special chars like pipe '|' are treated as literals and do not have their normal effect. Semi quoted inseparable text is where spaces are treated as a literal and do not end the argument but special chars are signifigant. Normal quoted text can be viewed as being a combination of the two semi quoted modes.

In addition to these modes there are some special rules for escaping the quotes. A backslash can be used to escape a quote in all of the modes, however a pair of quotes can be used to escape a quote, but that doing so puts the parser into "semi quoted seperable" mode. A new quote when in this mode puts the parser into "semi quoted inseperable" mode, which if terminated with a lone quote returns to SQS and if terminated with a pair returns to unquoted mode. This behaviour can be observed by observing the behaviour of special char handling (the pipe is useful as it doesnt create weird files, instead gives an error when the pipe is treated as special).

I put your snippet into a script for legibility purposes, here are some results:

# quoted D:\>pq "|" (|) # quoted ends in pair, which is treated as a literal " and a mode shif +t D:\>pq "|"" (|") # ... which is observable here as the pipe is treated as a literl, thi +s is # semi-quoted-seperable mode. D:\>pq "|"" | (|") (|) # here we see that the lone quoted section in the second argument is # semit-quoted-inseperable. the space is literal but ... D:\>pq "|"" " " (|") ( ) # ... the special chars like pipe are not. D:\>pq "|"" " | The syntax of the command is incorrect. # here we see that SQS reverts to SQI after the second lone quote. D:\>pq "|"" " " |" (|") ( ) (|) # but it reverts to unquoted after a second double quote... D:\>pq "|"" " "" |" '"' is not recognized as an internal or external command, operable program or batch file. # ... which this demonstrates D:\>pq "|"" " "" foo" (|") ( ") (foo)

I think that these rules are sufficient to explain all of your examples. However I will say that its really sucky that MS doesnt fix this mess. :-)


---
demerphq

    First they ignore you, then they laugh at you, then they fight you, then you win.
    -- Gandhi


Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Windows command line
by CountZero (Bishop) on Oct 19, 2003 at 08:57 UTC
    Well if MS fixes up this mess, they probably mess up something which is fixed. ;-)

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law