git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Replace git-cvsimport with a rewrite that fixes major bugs.

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Jan 3, 2013, 16:24 UTC
Message-ID
<50E5B0B2.7060205@alum.mit.edu>
In-Reply-To
<7vip7expd8.fsf@alter.siamese.dyndns.org>
On 01/03/2013 04:22 PM, Junio C Hamano wrote:
Show 7 quoted lines
> Antoine Pelisse <apelisse@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.

Show 14 quoted lines
>> 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 [1]; when in doubt, one can view older versions of the library documentation, which are all available online [2].

Michael

[1] http://docs.python.org/2/library/ [2] http://www.python.org/doc/versions/

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
Previous: Junio C Hamano
Message 24 of 24 in “Replace git-cvsimport with a rewrite that fixes major bugs.”
  1. Replace git-cvsimport with a rewrite that fixes major bugs.Eric S. Raymond, Jan 1, 2013
  2. Junio C HamanoJan 1, 2013
  3. Eric S. RaymondJan 2, 2013
  4. Junio C HamanoJan 2, 2013
  5. Jonathan NiederJan 2, 2013
  6. Eric S. RaymondJan 2, 2013
  7. Jonathan NiederJan 2, 2013
  8. Eric S. RaymondJan 2, 2013
  9. Martin LanghoffJan 2, 2013
  10. Eric S. RaymondJan 2, 2013
  11. Thomas BergJan 2, 2013
  12. Martin LanghoffJan 2, 2013
  13. Eric S. RaymondJan 2, 2013
  14. Martin LanghoffJan 2, 2013
  15. Jonathan NiederJan 2, 2013
  16. Andreas SchwabJan 2, 2013
  17. Junio C HamanoJan 2, 2013
  18. Eric S. RaymondJan 2, 2013
  19. Junio C HamanoJan 2, 2013
  20. Chris RorvickJan 3, 2013
  21. Junio C HamanoJan 3, 2013
  22. Antoine PelisseJan 3, 2013
  23. Junio C HamanoJan 3, 2013
  24. Michael HaggertyJan 3, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.