[issue20451] os.exec* mangles argv on windows (splits on spaces, etc)

Raymond Hettinger report at bugs.python.org
Mon Jul 14 03:53:55 CEST 2014


Raymond Hettinger added the comment:

> I believe the problem lies with the way that Windows implements 
> the 'exec' functions.

Yes, that is that cause of the observed behavior.  See the first note in the remarks section on the relevant MSDN entry at http://msdn.microsoft.com/en-us/library/431x4c1w.aspx :

"""
Spaces embedded in strings may cause unexpected behavior; for example, passing _exec the string "hi there" will result in the new process getting two arguments, "hi" and "there". If the intent was to have the new process open a file named "hi there", the process would fail. You can avoid this by quoting the string: "\"hi there\"".
"""

The 'exec' functions are more low level and more arcane than most people would like.  Python exposes that functionality with all its beauty and all its warts.  David Murray is right in saying that you likely need one of the higher level modules such as subprocess with shell=True.

I looked through the code in Modules/posixmodule.c and didn't any code on our part that exacerbates the behavior.

Knowing that the cause is the underlying function still leaves the question of whether to apply a patch the mitigates the problem (possibly breaking some code that relies on the existing behavior) or whether to live with the facts-of-life that accompany low level O/S functions.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20451>
_______________________________________


More information about the Python-bugs-list mailing list