[Python-Dev] Re: subprocess - updated popen5 module

Peter Astrand astrand at lysator.liu.se
Tue Oct 12 09:25:14 CEST 2004

On Mon, 11 Oct 2004, Guido van Rossum wrote:

> > So, can the subprocess module be accepted? If not, what needs to be done?
> FWIW, I've given Peter some feedback, but in general I think this code
> is ready for inclusion into 2.4. I hope it's not too late.

Sounds great.

> recommendation on the call/callv issue is to get rid of callv(),

callv() has now been removed.

> instead let call() interpret multiple string args as such; a single
> string arg will be interpreted as a whole command line, per Popen(); if
> you want a single file arg you have to enclose it in [...].)

I haven't done any changes to call(): it passes the arguments directly to
Popen(), just like before. I would prefer if we could keep it that way;
it's so nice to have a short and simple description of the function:

    Run command with arguments.  Wait for command to complete, then
    return the returncode attribute.

If we should do any more changes to handling of multiple
args/strings/sequences, we should probably do it to the Popen class

But I think we have found a good API now. Here's the documentation:

args should be a string, or a sequence of program arguments.  The
program to execute is normally the first item in the args sequence or
string, but can be explicitly set by using the executable argument.

On UNIX, with shell=False (default): In this case, the Popen class
uses os.execvp() to execute the child program.  args should normally
be a sequence.  A string will be treated as a sequence with the string
as the only item (the program to execute).

On UNIX, with shell=True: If args is a string, it specifies the
command string to execute through the shell.  If args is a sequence,
the first item specifies the command string, and any additional items
will be treated as additional shell arguments.

On Windows: the Popen class uses CreateProcess() to execute the child
program, which operates on strings.  If args is a sequence, it will be
converted to a string using the list2cmdline method.  Please note that
not all MS Windows applications interpret the command line the same
way: The list2cmdline is designed for applications using the same
rules as the MS C runtime.

/Peter Åstrand <astrand at lysator.liu.se>

More information about the Python-Dev mailing list