[Python-Dev] subprocess shell=True on Windows doesn't escape ^ character

R. David Murray rdmurray at bitdance.com
Fri Jun 13 14:40:17 CEST 2014


On Fri, 13 Jun 2014 16:57:49 +1200, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nikolaus Rath wrote:
> > you almost certainly want to do
> > 
> > Popen(['/bin/sh', 'for i in `seq 42`; do echo $i; done'], shell=False)
> > 
> > because if your shell happens to be tcsh or cmd.exe, things are going to
> > break.
> 
> On Unix, the C library's system() and popen() functions
> always use /bin/sh, NOT the user's current login shell,
> for this very reason.
> 
> I would hope that the Python versions of these, and also
> the new subprocess stuff, do the same.

They do.

> That still leaves differences between Unix and Windows,
> but explicitly naming the shell won't help with that.

There are some non-windows platforms where /bin/sh doesn't
work (notably Android, where it is /system/bin/sh).  See
http://bugs.python.org/issue16353 for a proposal to create a standard
way to figure out what the system shell should be for Popen's use.
(The conclusion for Windows was to hardcode cmd.exe, though
that isn't what the most recent patch there implements.)

--David


More information about the Python-Dev mailing list