Eryk Sun <eryk...@gmail.com> added the comment:

The behavior of list2cmdline with double quotes is intentional. It supports 
passing literal quote characters in the command line for applications that use 
VC++ argv parsing, WINAPI CommandLineToArgvW, or in general any application 
that adheres to these rules when parsing its command line [1]. (Not all do -- 
such as cmd.exe -- in which case we have to pass a custom command line instead 
of relying on listcmdline.) 

If we have a command line already, then generally the best thing to do in 
Windows is pass it as is. Don't split it and rebuild it via list2mdline.

The problem I see is using shlex.split in Windows. posix=False doesn't  mean it 
can handle Windows command lines properly. The shlex module is meant to 
tokenize a command line like a Unix shell. With posix=False, quote characters 
aren't stripped out, i.e. it preserves the double quotes in '"spam"'. But with 
posix=True it's just as wrong for Windows because it tokenizes "'spam & eggs'" 
as ['spam & eggs']. This is wrong because single quotes generally have no 
special meaning in Windows command lines (certainly not for CreateProcessW, 
CommandLineToArgvW, and VC++ argv handling). They should be retained as literal 
characters. Thus the proper result in Windows is "'spam & eggs'" -> ["'spam", 
'&', "eggs'"].

[1]: https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37659>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to