Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > On Windows, how do I protect arguments to shell scripts launched with subprocess?

Reply
Thread Tools

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

 
 
arve.knudsen@gmail.com
Guest
Posts: n/a
 
      02-08-2011
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Shared memory python between two separate shell-launched processes Charles Fox (Sheffield) Python 9 02-12-2011 02:19 PM
Re: Shared memory python between two separate shell-launched processes Miki Tebeka Python 0 02-11-2011 06:18 PM
What is required for perl scripts to run correct when launched from rc scripts on HPUX 11? deanjones7@gmail.com Perl Misc 13 09-10-2007 11:58 AM
Stupid question: Making scripts python-scripts Jan Danielsson Python 8 07-22-2005 12:20 AM



Advertisments