Need help with input redirection

Batista, Facundo FBatista at uniFON.com.ar
Thu May 8 07:40:04 EDT 2003


#- I'm looking for a way to redirect input from one program 
#- into a python 
#- program.  For example:
#- 
#- $tcpdump | pythonprog.py
#- 
#- The objective is to take the text output of one running 
#- program and pipe 
#- it into the python program for parsing and processing.  It 
#- is important 
#- during this process that I:
#- 
#- 1)  Not use a file as an intermediate step (I can already do 
#- that), and
#- 2)  The program feeding my python program *does not 
#- terminate*.  That 
#- is, it keeps running and my python program keeps independently 
#- processing the input and doing stuff with it while the other program 
#- continuously feeds it.

The problem here is that the OS waits for tcdump to terminate to pass the
data to pythonprog.py (I'm not 100% sure about this, am I wrong?)

My approach would be to popen(tcpdump) and then read from its stdout.

.	Facundo






More information about the Python-list mailing list