Popen and Razor client

Donn Cave donn at u.washington.edu
Fri Aug 23 15:59:26 EDT 2002


Quoth Toorop <toorop at cyborgnation.org>:
| Bonjour ,
|
|   First escuse my english.....
(It is not perfect, I must say, but it has not kept you from
 delivering a very clear statement of your problem.)

|   Second : i want to make a razor client with python in order to add
|   this function to my mail scanner (which is in python too).
|
|   But i'm not ok with popen.
|
|   The normal use of razor is :
|
|   $ cat mail | razor-check
|
|   If the exit status of razor-check is 1, the mail is ok, if the exit
|   status is 0 the mail is considered has spam for razor.
|
|   In my script, the mail to test is in a string :test_spam.
|
|   My script :
| def is_spam_for_razor(test_spam) :
|     import popen2
|     razor_check="/usr/bin/razor-check"
|
|     in_razor,out_razor=popen2.popen2(razor_check)
|     reponse=out_razor.write(test_spam)
|     reponse2=in_razor.readline()
|     print reponse2
|
|     #close
|     in_razor.close()
|     out_razor.close()
|
|
|   But has you can expect, it doesn't work, the script wait, wait,wait...
|   If someone could help me.

I suggest you move the last line, out_razor.close(), to before the
in_razor.readline().  That will tell razor-check that there's no
more data, and it can finish up.

Then you will of course want to refine this program to determine
what its exit status was, 0 or not.  If you replace popen2.popen2(cmd)
with popen2.Popen3(cmd), you'll a class instance with fromchild and
tochild members and a wait() method;  os.WEXITSTATUS(xx.wait()) is
razor's exit status.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list