This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Jim.Jewett
Recipients Jim.Jewett
Date 2014-06-13.19:10:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1402686648.11.0.572463197198.issue21753@psf.upfronthosting.co.za>
In-reply-to
Content
Inspired by https://mail.python.org/pipermail/python-dev/2014-June/135029.html and the following thread.  

"""
Normal Windows behavior:

  >hg status --rev ".^1"
  M mercurial\commands.py
  ? pysptest.py

  >hg status --rev .^1
  abort: unknown revision '.1'!

So, ^ is an escape character. See
http://www.tomshardware.co.uk/forum/35565-45-when-special-command-line
"""

It probably isn't possible to pre-escape commands for every possible command interpreter, but it makes sense to get the standard shells right. 

In fact, global function list2cmdline already exists (and is apparently specific to the Microsoft compiler), but ... its rules are not the same as those of the default windows shell.  (Per the tomshardware link, those rules (for windows) did change a while back.)

I propose a similar list2shellcmd function.  Based on my own very incomplete information, it would currently look like:

def list2shellcmd(seq):
    """Turn the sequence of arguments into a single command line, with escaped characters."""
    if mswindows:
        line=list2cmdline(seq).replace("^", "^^")
    else:
        line=" ".join(seq)
    return line

but there may well be escapes (such as \) that are appropriate even for posix.

Note that related issue http://bugs.python.org/issue7839 proposes a larger cleanup, such as forbidding the problematic functionality entirely.
History
Date User Action Args
2014-06-13 19:10:48Jim.Jewettsetrecipients: + Jim.Jewett
2014-06-13 19:10:48Jim.Jewettsetmessageid: <1402686648.11.0.572463197198.issue21753@psf.upfronthosting.co.za>
2014-06-13 19:10:48Jim.Jewettlinkissue21753 messages
2014-06-13 19:10:47Jim.Jewettcreate