Why do Windows programs parse command-line switches out of their executable's path? (The latter being what is commonly known as argv[0]
.)
For example, xcopy:
C:\Temp\foo>c:/windows/system32/xcopy.exe /f /r /i /d /y * ..\bar\
Invalid number of parameters
C:\Temp\foo>c:\windows\system32\xcopy.exe /f /r /i /d /y * ..\bar\
C:\Temp\foo\blah -> C:\Temp\bar\blah
1 File(s) copied
What behavior should I follow in my own programs?
Are there many users that expect to type command-line switches without a space (e.g. program/?
instead of program /?
), and should I try to support this, or should I just report an error and exit immediately?
What other caveats do I need to be aware of? (In addition to Anon.'s comment below that "debug/program" runs debug.exe from PATH even if "debug\program.exe" exists.)