--- fcntlmodule.c.orig Sat Jul 29 11:43:13 2006 +++ fcntlmodule.c Fri Nov 24 12:32:07 2006 @@ -546,6 +546,11 @@ if (ins(d, "DN_MULTISHOT", (long)DN_MULTISHOT)) return -1; #endif +/* For systems like AIX that have F_CLOSEM to close multiple fds */ +#ifdef F_CLOSEM + if (ins(d, "F_CLOSEM", (long)F_CLOSEM)) return -1; +#endif + #ifdef HAVE_STROPTS_H /* Unix 98 guarantees that these are in stropts.h. */ INS(I_PUSH); --- popen2.py.orig Fri Jul 21 13:36:31 2006 +++ popen2.py Mon Nov 27 16:50:00 2006 @@ -8,6 +8,7 @@ import os import sys +import fcntl __all__ = ["popen2", "popen3", "popen4"] @@ -79,11 +80,18 @@ def _run_child(self, cmd): if isinstance(cmd, basestring): cmd = ['/bin/sh', '-c', cmd] - for i in xrange(3, MAXFD): - try: - os.close(i) - except OSError: - pass + try: + if fcntl.F_CLOSEM: + try: + fcntl.fcntl(3, fcntl.F_CLOSEM, 0) + except OSError: + pass + except AttributeError: + for i in xrange(3, MAXFD): + try: + os.close(i) + except OSError: + pass try: os.execvp(cmd[0], cmd) finally: