Question about pipes/os.popen

Steve Holden steve at
Fri Sep 15 20:38:17 CEST 2006

Kevin Walzer wrote:
> I'm trying to structure a Python script that streams output over a pipe.
> Here is my code:
> import os
> cmd = os.popen('echo foo | sudo -S /usr/sbin/tcpdump -en1')
> This returns output of "". I'm expecting the standard output of "tcpdump
> -en1". How does one read unbuffered output over a pipe before the pipe
> is closed in Python? Because I want the output to be updated in real
> time, writing to a temporary file and then reading that data isn't
> feasible.
> I'm not sure what I'm doing wrong here.
Probably expecting sudo to read the standard input for its password.

First of all, sudo doesn't always ask for your password. Secondly, when 
it does I'm pretty sure it will take care to try and do it on the 
controlling tty, not by reading stdin.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Recent Ramblings

More information about the Python-list mailing list