A tale of two execs

Matt Nordhoff mnordhoff at mattnordhoff.com
Mon Feb 23 12:07:04 EST 2009


aha wrote:
> Hello All,
>   I am working on a project where I need to support versions of Python
> as old as 2.3. Previously, we distributed Python with our product, but
> this seemed a bit silly so we are no longer doing this.  The problem
> that I am faced with is that we have Python scripts that use the
> subprocess module, and subprocess is not available in Python 2.3.
> Below is the strategy I am thinking about using, however if, you have
> better ideas please let me know.
> 
> def runner(cmd, stdin, stdout, ...):
>   try:
>     import subprocess
>     sbm = 1
>   except:
>     sbm = 0
> 
>   # Now do something
>   if sbm:
>     process = subporcess(...)
>   else:
>     import popen2
>     process = popen2.Popen4(...)
> 
> Has anyone else run into a situation similar to this one?

FWIW, the Mercurial project went the other way: They wrote "popen2",
"popen3" and "Popen3" functions that were wrappers around subprocess:

<http://selenic.com/repo/hg-stable/file/dd970a311ea8/mercurial/util.py#l52>
-- 



More information about the Python-list mailing list