[Python-ideas] [Python-Dev] subprocess not escaping "^" on Windows

Chris Angelico rosuav at gmail.com
Sun Jan 7 12:18:06 EST 2018

Redirecting this part of the conversation to python-ideas.

On Mon, Jan 8, 2018 at 3:17 AM, Christian Tismer <tismer at stackless.com> wrote:
> As a side note: In most cases where shell=True is found, people
> seem to need evaluation of the PATH variable. To my understanding,
>>>> from subprocess import call
>>>> call(("ls",))
> works in Linux, but (with dir) not in Windows. But that is misleading
> because "dir" is a builtin command but "ls" is not. The same holds for
> "del" (Windows) and "rm" (Linux).

That's exactly what shell=True is for - if you want a shell feature,
you use the shell. What exactly would emulate_shell do? Would it
simply do a $PATH or %PATH% search, but otherwise function as
shell=False? Would it process redirection? Would it handle
interpolations? I think not, from your description:

> Perhaps it would be a good thing to emulate the builtin programs
> in python by some shell=True replacement (emulate_shell=True?)
> to match the normal user expectations without using the shell?

but it becomes difficult to draw the line. For instance, with
emulate_shell=True, what would you do with all the sh/bash built-ins:


I'm thinking especially of the commands where bash has its own
handling of something that could otherwise be found in $PATH, like
pwd, time, and echo, but shells can do a lot of other things too.

When do you actually want to execute a shell built-in from Python but
without using the shell itself? You give the example of ls/dir, but if
that ever comes up in real-world code, I'd toss it out and recommend a
cross-platform os.listdir or equivalent. There are plenty of times
I've wanted a really quick way to redirect a standard stream from
Python, but that isn't part of what you're recommending. Can you give
a real-world example that would be improved by this?

I know this was just a side note in your original, but I'd like to
hear more about what would make it useful.


More information about the Python-ideas mailing list