why does popen2 silently ignore IOError?

Neil Schemenauer nas at python.ca
Wed Feb 20 18:56:23 EST 2002


os.system() and os.popen() are security nightmares because they use the
shell (all kinds of quoting problems).  I don't like popen2 either
because getting the exit status of the command is inconvenient, IMHO.  I
wrote a little module for executing child processes.  You can get it
from here:

    http://arctrix.com/nas/python/child_process.py

Examples:

    >>> p = child_process.execute(("ls", "/"))
    >>> p.readline()
    'bin\n'
    >>> p.readline()
    'boot\n'
    >>> p.close()
    >>>

    >>> p = child_process.execute(("cat",))
    >>> p.write("hello world\n")
    >>> p.stdin.close()
    >>> p.read()
    'hello world\n'
    >>> p.close()
    >>>

    >>> p = execute(("false",))
    >>> p.close()
    256
    >>>

I would like to get something into the standard distribution but I need
to come up with a better module name first.  Any suggestions?

  Neil




More information about the Python-list mailing list