[Tutor] Pipe variable to external command
Jeffrey Rice
jeffrice at finity.org
Thu May 12 06:39:47 CEST 2005
Hi,
I am working on getting comfortable with Python, and am trying to rewrite
some of my old (clumsy) bash scripts into python.
I am having a little problem with how to pipe a variable's contents to an
external command. Essentially, I have a variable that contains the
contents of a variable that I want to feed to a series of external commands
(clamav and spamassassin).
EMAIL contains the full email message, and CLAMAV contains the path to the
clamscan bin (and necessary flags). I have tested this on the command line
and it works (so I know the command syntax is correct), but in my python
script it is clear that nothing is getting piped to the scanner.
CLAMAV_h= os.popen(CLAMAV, 'w')
CLAMAV_h.write(EMAIL)
CLAM_RESULT=CLAMAV_h.close()
print CLAM_RESULT
I can make this work by writing to a temp file and scanning that, but I
would like to avoid having to write to and read from a temp file at every
step. I expect I am making a very basic error, stemming from my tackling a
(perhaps?) more advanced problem at this early stage. But one can only get
so far with "Hello World"....
Many thanks,
Jeff
* * * * * * *
Jeffrey Rice || jeffrice at finity.org || www.finity.org
More information about the Tutor
mailing list