popen(), sendmail: Success?

Donn Cave donn at drizzle.com
Thu Apr 10 17:56:26 EDT 2003


Quoth mb at muenster.de (Martin Bless):
| To send mails from Python here's the example my provider provides:
| This http://faq.puretec.de/skripte/python/3.html
|
| The relevant lines are these:
|
| sendmail = os.popen("/usr/lib/sendmail -t", "w")
| sendmail.write(msg)
| sendmail.close()
|
| This works just fine. But is it enough? How do I know the operation
| succeeded?
|
| I've read the docs about os.popen[234] and the module popen2 but I'm
| not sure where to go. And since experimentation isn't easy in this
| case I'd appreciate some hints or a concrete example very much.

But since you use os.popen, you would want to read the docs for popen.

popen(command[, mode[, bufsize]])
   Open a pipe to or from command. The return value is an open file
   object connected to the pipe, which can be read or written depending
   on whether mode is 'r' (default) or 'w'. The bufsize argument has the
   same meaning as the corresponding argument to the built-in open()
   function. The exit status of the command (encoded in the format
   specified for wait()) is available as the return value of the close()
   method of the file object, except that when the exit status is zero
   (termination without errors), None is returned. 

>From this you can see that if the command completes without errors,
sendmail.close() returns None.

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list