[Tutor] reading from stdin
nick at javacat.f2s.com
Wed Mar 2 09:19:51 CET 2005
many thanks for pointing that out. It all helps :)
On Tue, 2005-03-01 at 17:35 -0600, Hugo González Monteverde wrote:
> Everypne else has answered pretty muh about this. I just want to add
> that if you want to read noncanonically (less thana line ending in "\n"
> you'll have to do it char by char =( AFAIK, there's no way to redefine a
> separator por readlines() (other than \n..)
> Nick Lunt wrote:
> > Hi folks,
> > I've been pondering how to get python to read from a pipe outside of
> > itself, sort of.
> > For example I tried a simple python prog to do a grep, eg
> > # ps -e | myprog.py cron
> > would give this output
> > 3778 ? 00:00:00 crond
> > same as
> > # ps -e | grep cron
> > The way I did this was to use sys.stdin.readlines() to get the output
> > from the pipe.
> > Here is the program:
> > [code]
> > import sys, glob
> > args = sys.stdin.readlines() # found on the net
> > pat = sys.argv
> > for i in args:
> > if (i.find(pat) != -1):
> > print i,
> > [/code]
> > My question is am I getting the output from the pipe in the correct
> > way ? The way Im doing it works (so far) but should I be doing it
> > another way ?
> > Many thanks
> > Nick .
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor