[issue8972] subprocess.list2cmdline doesn't quote the & character
report at bugs.python.org
Sun Jun 13 00:48:21 CEST 2010
shypike <shypike at sabnzbd.org> added the comment:
A work-around could be that the caller puts double quotes around the individual elements of the sequence that need it.
However, this won't work because list2cmdline doesn't handle backslash quoting properly. An element like r'"foo"' is translated to r'\"foo\"'. This is incorrect because cmd.exe cannot handle this. The backslash may be appropriate for embedded quotes (like in r'foo"bar'), but not for outer quotes (like in r'"foobar"').
The user shouldn't have to worry with adding quotes anyway, so it would be better to demand that '|' and '&' are passed as separate elements in the sequence. Example ['echo', 'foo', '&', 'bar'].
When someone passes ['echo', 'foo&bar'], it is very obvious that r'echo "foo&bar"' is expected and not r'echo foo & bar'.
I have added a patch for this way of working of list2cmdline.
Added file: http://bugs.python.org/file17650/list2cmdline_proper_fix.patch
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list