On 01/03/2013 04:22 PM, Junio C Hamano wrote: > Antoine Pelisse <apeli...@gmail.com> writes: > >>> Doesn't Python come with a standard subprocess module that lets you >>> spawn external programs safely, similar to the way Perl's list form >>> open(), e.g. "open($fh, "-|", 'git', @args)", works? > > ... and of course a more boring "system('git', $subcmd, @args)", as well.
Python's os.system() takes exactly one argument, which must be a string, and executes it in a subshell. subprocess is indeed the way to go. >> You mean something like this: >> >> p1 = subprocess.Popen([backend.command()], stdout=subprocess.PIPE) >> subprocess.Popen(["git", "fast-import", "--quiet"] + gitopts, >> cwd=outdir, stdin=p1.stdout) >> >> Assuming gitopts is a list rather than a string. (care must be taken >> with backend.command() also) > > Yes. > > I vaguely recall that the subprocess module once used to be one > portability issue but that was between Python 2.3 and 2.4 or some > ancient history, and it should no longer be relevant. subprocess was added in Python 2.4, and the above example should work fine in any version >= 2.4. But please note that other functions have been added to the module since then, like check_call() (v2.5), check_output (v2.7), and some methods were added to the Popen object in v2.6. Such things are documented pretty reliably in the Python library documentation ; when in doubt, one can view older versions of the library documentation, which are all available online . Michael  http://docs.python.org/2/library/  http://www.python.org/doc/versions/ -- Michael Haggerty mhag...@alum.mit.edu http://softwareswirl.blogspot.com/ -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html