Question about pipes/os.popen
Steve Holden
steve at holdenweb.com
Fri Sep 15 14:38:17 EDT 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')
> cmd.read()
>
> 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.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list