3 ms·
It'd be interesting to know why Microsoft implemented parameter parsing that way. Maybe they decided to let the executable parses its own parameters as an opti
by laurent123456 9y ago
It'd be interesting to know why Microsoft implemented parameter parsing that way. Maybe they decided to let the executable parses its own parameters as an optimisation - it means if the executable doesn't care about its arguments (or doesn't have any, like most GUI programs), an extra step is saved.
Except now it's clear it was a premature optimisation, if it takes 10 pages to document the parsing behaviour, which probably also cost millions of wasted developer hours fixing weird corner cases.
Maybe at that time they thought, "well programmers can just call GetCommandLine() to get the args in a consistent way".
- digi_owl 9y agoI suspect it is a remnant of the DOS days.
- userbinator 9y agoThe "command line as a single string" dates to CP/M if not earlier: https://en.wikipedia.org/wiki/Zero_page_(CP/M) https://en.wikipedia.org/wiki/Zero_page_(CP/M) I don't think it's an optimisation, but a design choice of simplicity; in fact, CP/M (and DOS) would parse the first two arguments if present, and put the results into the filename fields of the two default FCBs, allowing programs which take two filename arguments (traditionally, an input and an output) to be implemented easily without having any commandline parsing logic of their own. More info on that here: http://www.gaby.de/cpm/manuals/archive/cpm22htm/ch5.htm http://www.gaby.de/cpm/manuals/archive/cpm22htm/ch5.htm It would be interesting to trace the origins of command-line parameter passing design even further, to the mainframe OSes that came before UNIX, but I'm not so familiar with them. Edit: OpenVMS appears to also pass a plain string to the process, which is then parsed within: http://hoffmanlabs.org/vmsfaq/vmsfaq_015.html http://hoffmanlabs.org/vmsfaq/vmsfaq_015.html (section 10.3)
- vram22 9y agoMaybe they could have designed it to have the ability to do it either way, i.e. based on a flag of some sort, the Windows either parses the args (does the shell-level interpretations such as of quotes and other metacharacters), or does not; in either case, it then passes the (parsed or unparsed) args to the command. That flag would have to be understood and acted on by Windows, though, not the individual commands, since the action has to happen (or not) before the commands gets the args. Might be clunky, not thought through the idea in detail.