On Windows, how do I protect arguments to shell scripts launched with subprocess?

Discussion in 'Python' started by arve.knudsen@gmail.com, Feb 8, 2011.

  1. Guest

    Hi

    Since upgrading to Python 2.7, I've run into the problem that when I
    launch shell scripts (.e.g, *.bat) via subprocess.Popen (with False
    for the 'shell' option, mind you), the arguments get interpreted by
    the shell. For instance, the '|' character, no longer gets passed
    verbatim to the script. What is now the correct way to protect
    arguments passed as a list to subprocess.Popen? I tried enclosing each
    argument in double quotes, but subprocess in turn thwarts my attempt,
    by protecting each double quote with a backslash! For example, if I
    were to pass ['"|"'] as the argument list to subprocess.Popen, it'd be
    transformed like this:
    >>> subprocess.list2cmdline(['"|"'])

    '\\"|\\"'

    Thanks,
    Arve
     
    , Feb 8, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vinay
    Replies:
    2
    Views:
    4,007
    =?ISO-8859-2?Q?Dra=BEen_Gemi=E6?=
    Jul 28, 2006
  2. Samuel A. Falvo II
    Replies:
    0
    Views:
    486
    Samuel A. Falvo II
    Oct 8, 2008
  3. Charles Fox (Sheffield)
    Replies:
    9
    Views:
    736
    Adam Skutt
    Feb 12, 2011
  4. Replies:
    13
    Views:
    534
    Anno Siegel
    Sep 10, 2007
  5. s71murfy
    Replies:
    2
    Views:
    64
    Mark H Harris
    May 1, 2014
Loading...

Share This Page