Index: distutils/spawn.py =================================================================== --- distutils/spawn.py (revision 81963) +++ distutils/spawn.py (working copy) @@ -40,20 +40,30 @@ raise DistutilsPlatformError, \ "don't know how to spawn programs on platform '%s'" % os.name +# Derived from http://technet.microsoft.com/en-us/library/cc723564.aspx +# Also added ", which is special +_nt_quote_chars = ' "&()<>^|' + def _nt_quote_args(args): """Quote command-line arguments for DOS/Windows conventions. - - Just wraps every argument which contains blanks in double quotes, and - returns a new argument list. + Just wraps every argument which contains special characters in double + quotes, and returns a new argument list. """ - # XXX this doesn't seem very robust to me -- but if the Windows guys - # say it'll work, I guess I'll have to accept it. (What if an arg - # contains quotes? What other magic characters, other than spaces, - # have to be escaped? Is there an escaping mechanism other than - # quoting?) for i, arg in enumerate(args): - if ' ' in arg: + # if any reserved characters are in an arg, quote it + needquote = False + for c in arg: + if c in _nt_quote_chars: + needquote = True + if needquote: + # also escape (by doubling the character) quotes, and a backslash + # followed by a quote + arg = arg.replace('\\"', '\\\\"') + if arg[-1:] == '\\': + arg = arg[:-1] + '\\\\' + arg = arg.replace('"', '""') args[i] = '"%s"' % arg + return args def _spawn_nt(cmd, search_path=1, verbose=0, dry_run=0):