-
Notifications
You must be signed in to change notification settings - Fork 1
Windows Command Line
Commandline | arg1 | arg2 | arg3 |
---|---|---|---|
"abc" d e |
abc |
d |
e |
a\\\b d"e f"g h |
a\\\b |
de fg |
h |
a\\\"b c d |
a\"b |
c |
d |
a\\\\"b c" d e |
a\\b c |
d |
e |
c:\a_dir\ "\sp ace\" |
c:\a_dir\ |
\sp ace\ |
|
"a ""b"" c" |
a "b" c |
||
"""a b c""" |
"a b c" |
||
"a"" b c |
a" b c |
||
a "b" c |
a |
b |
c |
a "b c" "d e |
a |
b c |
d e |
a \"b\" c |
a |
"b" |
c |
- [http://msdn.microsoft.com/en-us/library/17w5ykft%28v=vs.85%29.aspx]
- [http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx]
- Good detail here [http://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts]
The above apply to generic arguments to a process where that process uses C run-time via CommandLineToArgv()
to split the command line into argc
& argv
's. In particular console applications, which use ANSI*, get parameters via int main( int argc, char * argv[] )
such as used by openscad.com
* see here for ANSI v's Unicode, basically "The main and WinMain functions cannot return Unicode strings".
Commandline | argc @ | argv[1] | argv[2] | argv[3] |
---|---|---|---|---|
c:\nospaces\prog.exe p1 p2 |
c:\nospaces\prog.exe |
p1 |
p2 |
|
"c:\spa ces\prog.exe" "p 1" p 2 |
"c:\spa ces\prog.exe" |
p 1 |
p |
2 |
aprog "c:\dir w spaces\" |
aprog |
c:\dir w spaces\ |
||
(note " in the third line above is not an escaped double-quote, it is the closing quote of a pair) |
@ Note "By convention, argv[0] is the command with which the program is invoked. However, it is possible to spawn a process using CreateProcess and if you use both the first and second arguments (lpApplicationName and lpCommandLine), argv[0] may not be the executable name; use GetModuleFileName to retrieve the executable name, and its fully-qualified path."
openscad.com uses _popen
to run openscad.exe with the reconstructed command line via the windows command interpreter, hence cmd.exe parses the command line BEFORE it gets to CommandLineToArgv()
, this is where parameters with special characters need to be enclosed in a pair of double-quotes as they are meaningful to cmd.exe. From here the special characters are:
& < > [ ] { } ^ = ; ! ' + , ` ~ [space] [tab]
Double-quote is not a special character in itself, a "
(only, without any of the above) in a parameter does not need to be enclosed in a pair of double-quotes, but needs to be escaped, either with a backslash (\"
), or another double-quote (""
).