|
From: Keith M. <kei...@us...> - 2014-06-25 00:06:04
|
On 24/06/14 23:11, Yuri Kanivetsky wrote: > If I understand you correctly, using single quotes is no better than using > double quotes here. Both commands: > > $ cmd //c '"cmd" /c echo test' > $ cmd //c "\"cmd\" /c echo test" > > produce the same command line: > > c:\Windows\system32\cmd.exe /c "\"cmd\" /c echo test" Correct. The inner pair of double quotes are literal; according to both http://msdn.microsoft.com/en-us/library/a1y7w461.aspx and http://msdn.microsoft.com/en-us/library/17w5ykft.aspx when embedded within outer double quotes, (as Windows requires, because it doesn't attribute any significance to single quotes), these inner quotes must be escaped, to have them parsed as such. > And they doesn't do what they are supposed to do. The point here is to pass > the following command line to the process: > > c:\Windows\system32\cmd.exe /c ""cmd" /c echo test" Well, applying the parsing logic from each of those MSDN references, that is identically equivalent to c:\Windows\system32\cmd.exe /c cmd" /c echo test" because the first pair of quotes delimit an empty string. > AFAIR, some programs, amongst which are cmd, start, hstart, treat their > command line specially. When given things like `""cmd" /c echo test"`, they > just ignore the outer quotes or treat the whole thing as one big quoted > argument. Then such programs violate Microsoft's own parsing conventions, insofar as they apply to applications using their own C/C++ runtime. MSYS has been developed to interoperate with applications which do conform to those conventions, and accordingly DTRT. > So, is there a way to make it so that GetCommandLine() would > return exactly this: e:\showargv.exe ""c:\Program Files\foo" /k echo foo" ? That is doubtful, since the proper (conforming) intent would have been e:\showargv.exe "c:\Program Files\foo" /k echo foo or maybe e:\showargv.exe "c:\Program Files\foo" /k "echo foo" If you want to invoke arcane applications, with anomalous command line parsing conventions, then you may need a wrapper program, to parse the literal command line, interpreting the escapes according to the C/C++ runtime conventions, whence reconstructing the anomalously intended argument string, which it then forwards to CreateProcess(). Sometimes, you need to think outside the box. It could be that such a forwarding wrapper would be a useful addition to MSYS itself; perhaps Cesar, (the MSYS maintainer), could comment? -- Regards, Keith. |