Command line switches parsed out of executable's path

Posted by Roger Pate on Stack Overflow See other posts from Stack Overflow or by Roger Pate
Published on 2010-02-26T00:54:51Z Indexed on 2010/03/21 0:01 UTC
Read the original article Hit count: 299

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.)

© Stack Overflow or respective owner

Related posts about Windows

Related posts about command-line-arguments