why does popen2 silently ignore IOError?

Graham Guttocks graham_guttocks at yahoo.co.nz
Tue Feb 19 20:12:25 EST 2002


Can anyone explain why the popen2 module silently ignores an IOError?
I'm trying to use it to send mail instead of os.popen() to avoid
invoking /bin/sh.  

If all the command-line arguments are proper, things work fine, but if
I open a bogus command-line, popen2 doesn't complain, neither during
the write, nor close.  Take the following simple example:

% python2
Python 2.1.1 (#1, Aug 13 2001, 19:37:40) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-96)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import popen2
>>> def sendmail(s):
...     args = ['/bin/nonexistent', '-f', 'graham', 'testacct']
...     pp = popen2.popen2(args)[1]
...     pp.write(s)   
...     pp.close()
>>> sendmail('testing')

As you can see, no exceptions were raised despite the fact that there
is no such file as '/bin/nonexistent'.  Why is this?


Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games

More information about the Python-list mailing list