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

Chris Angelico rosuav at gmail.com
Fri Jun 13 04:25:36 CEST 2014


On Fri, Jun 13, 2014 at 12:11 PM, Nikolaus Rath <Nikolaus at rath.org> wrote:
> Can someone describe an use case where shell=True actually makes sense
> at all?
>
> It seems to me that whenever you need a shell, the argument's that you
> pass to it will be shell specific. So instead of e.g.
>
> Popen('for i in `seq 42`; do echo $i; done', shell=True)
>
> 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.

Some features, while technically shell-specific, are supported across
a lot of shells. You should be able to pipe output from one command
into another in most shells, for instance.

But yes, I generally don't use it.

ChrisA


More information about the Python-Dev mailing list