[Python-Dev] Re: subprocess - updated popen5 module
Peter Astrand
astrand at lysator.liu.se
Mon Oct 11 09:50:04 CEST 2004
On Sun, 10 Oct 2004, Jason Lunz wrote:
> > The biggest problem on Windows is that not all executables use the
> > Microsoft C runtime. Some use other C runtimes, others parse the
> > command line directly and don't use argv at all.
>
> So why does subprocess use cmdline2list() in the parent on unix to
> emulate the way a child subprocess might parse the string on windows?
> (But only if it's written in C, uses the MSC runtime, and uses the
> argv/argc handed to main() rather than calling GetCommandLine() itself).
> Why not emulate CommandLineToArgvW()? or something else entirely? I
> think it would be cleaner not to emulate anything at all.
One goal with subprocess is being able to write cross-platform
applications. For example, it should be possible to open up www.python.org
in Mozilla. The best way to write this is:
subprocess.call(["mozilla", "http://www.python.org"])
In this case, the list form is translated to the string form when running
on Windows.
Why allow the string form on UNIX? Answer: Symmetri, plus that some users
that has been using os.system() for a long time thinks it's nice to be
able to do:
subprocess.call("ls -l /foo/bar")
There's a risk that UNIX users might expect UNIX shell-like quoting
support rather than the MSC one, though.
> > The unix execv is just *different*. Both the Windows and the Unix
> > interfaces have capabilities the other doesn't offer.
>
> Well, the windows interface is a subset of the unix one. The length of
> argv on windows is limited to 1.
True, if we are talking about the UNIX exec functions. When executing
through a UNIX shell, the native interface is a string.
> > I think Peter's approach of supporting both forms - a single string as
> > a command line, and list of strings as an argv list, and converting
> > both to the more natural OS-native form as needed, is sensible (I
> > would, I argued for it when he was developing it!)
>
> I can see that it's trying to be symmetric and orthogonal, but I don't
> think that the result is worth it in this case. In what scenario is the
> use of cmdline2list() really useful?
I don't really have a good example.
If we should remove the cmdline2list stuff, what should happen if the
users passes a string on UNIX? Do you prefer:
1) Run through the shell (automatic shell=True).
or
2) A ValueError raised.
I guess alternative 1 is most intuitive. That would line up with popen2 as
well.
Anyone objecting to this change?
/Peter Åstrand <astrand at lysator.liu.se>
More information about the Python-Dev
mailing list