newbie pipe question
Michael
ms at cerenity.org
Tue Sep 5 20:24:57 EDT 2006
linuxnooby at yahoo.com.au wrote:
> Hi
>
> I want to write a python script that accepts input ( a single line of
> text) from another program (squid proxy) and sends back output ( a
> single line of text). I am not sure how to go about this
With a squid redirector (which is presumably what you mean) the things you
need to do are pretty simple:
* Read a line of text as sent to you by squid on stdin
* do some transform (if appropriate)
* Write the line back to stdout
The key thing you want to ensure is that you're not buffered. ie make sure
at the top of your python script you have "-u" after the python path.
ie your minimal script should look something like:
#!/usr/bin/python -u
import sys
while 1:
line = sys.stdin.readline()
# do something
sys.stdout.write(line)
Really quite simple you'll be pleased to see.
Regards,
Michael.
--
http://kamaelia.sourceforge.net/Home
http://yeoldeclue.com/blog
More information about the Python-list
mailing list