Re: Line-by-line processing when stdin is not a tty

2010-08-12 Thread Nobody
On Wed, 11 Aug 2010 18:49:26 -0700, RG wrote: > This doesn't explain why "cat | cat" when run interactively outputs > line-by-line (which it does). STDIN to the first cat is a TTY, but the > second one isn't. GNU cat doesn't use stdio, it uses read() and write(), so there isn't any buffering.

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Nobody wrote: > On Wed, 11 Aug 2010 10:32:41 +, Tim Harig wrote: > > >>> Usually you either > >>> need an option on the upstream program to tell it to line > >>> buffer explicitly > >> > >> once cat had an option -u doing exactly that but nowadays > >> -u seems to be ignored >

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Nobody
On Wed, 11 Aug 2010 10:32:41 +, Tim Harig wrote: >>> Usually you either >>> need an option on the upstream program to tell it to line >>> buffer explicitly >> >> once cat had an option -u doing exactly that but nowadays >> -u seems to be ignored >> >> http://www.opengroup.org/onlinepubs/009695

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 12:35, Tim Harig wrote: | > The buffering is a performance choice. Every write requires a context | > switch from userspace to kernel space, and availability of data in the | > pipe will wake up a downstream process blocked trying to read. | > It is far more efficient to do as few suc

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , RG wrote: > In article , > Tim Harig wrote: > > > On 2010-08-11, RG wrote: > > > In article , > > > Tim Harig wrote: > > > > > >> On 2010-08-11, RG wrote: > > >> > I'm writing a system in a different language but want to use a Python > > >> > library. I know of lots of ways

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Tim Harig wrote: > On 2010-08-11, RG wrote: > > In article , > > Tim Harig wrote: > > > >> On 2010-08-11, RG wrote: > >> > I'm writing a system in a different language but want to use a Python > >> > library. I know of lots of ways to do this (embed a Python interpreter, > >>

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, RG wrote: > In article , > Tim Harig wrote: > >> On 2010-08-11, RG wrote: >> > I'm writing a system in a different language but want to use a Python >> > library. I know of lots of ways to do this (embed a Python interpreter, >> > fire up a python server) but by far the easies

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Tim Harig wrote: > On 2010-08-11, RG wrote: > > I'm writing a system in a different language but want to use a Python > > library. I know of lots of ways to do this (embed a Python interpreter, > > fire up a python server) but by far the easiest to implement is to have > > the

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, RG wrote: > I'm writing a system in a different language but want to use a Python > library. I know of lots of ways to do this (embed a Python interpreter, > fire up a python server) but by far the easiest to implement is to have > the main program spawn a Python interpreter and

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Peter Otten <__pete...@web.de> wrote: > Grant Edwards wrote: > > > On 2010-08-11, Tim Harig wrote: > >> On 2010-08-11, RG wrote: > >>> When stdin is not a tty, Python seems to buffer all the input through > >>> EOF before processing any of it: > >>> > >>> [...@mickey:~]$ cat | pyt

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Cameron Simpson wrote: > On 11Aug2010 00:11, RG wrote: > | When stdin is not a tty, Python seems to buffer all the input through > | EOF before processing any of it: > | > | [...@mickey:~]$ cat | python > | print 123 > | print 456 > | 123 > | 456 > | > | Is there a way to get P

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Grant Edwards
On 2010-08-11, Peter Otten <__pete...@web.de> wrote: > Grant Edwards wrote: >>> If you want to handle stdin a single line at a time from inside of >>> your program, you can access it using sys.stdin.readline(). >> >> That doesn't have any effect on stdin buffering. > > "for line in stream"-styl

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Peter Otten
Grant Edwards wrote: > On 2010-08-11, Tim Harig wrote: >> On 2010-08-11, RG wrote: >>> When stdin is not a tty, Python seems to buffer all the input through >>> EOF before processing any of it: >>> >>> [...@mickey:~]$ cat | python >>> print 123 >>> print 456 >>> 123 >>> 456 >>> >>> Is there a w

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Grant Edwards
On 2010-08-11, Tim Harig wrote: > On 2010-08-11, RG wrote: >> When stdin is not a tty, Python seems to buffer all the input through >> EOF before processing any of it: >> >> [...@mickey:~]$ cat | python >> print 123 >> print 456 >> 123 >> 456 >> >> Is there a way to get Python to process input

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, Cameron Simpson wrote: > On 11Aug2010 10:32, Tim Harig wrote: >| On 2010-08-11, Wolfgang Rohdewald wrote: >| > On Mittwoch 11 August 2010, Cameron Simpson wrote: >| >> Usually you either >| >> need an option on the upstream program to tell it to line >| >> buffer explicitly >| > >

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 10:32, Tim Harig wrote: | On 2010-08-11, Wolfgang Rohdewald wrote: | > On Mittwoch 11 August 2010, Cameron Simpson wrote: | >> Usually you either | >> need an option on the upstream program to tell it to line | >> buffer explicitly | > | > once cat had an option -u doing exactly that

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, Wolfgang Rohdewald wrote: > On Mittwoch 11 August 2010, Cameron Simpson wrote: >> Usually you either >> need an option on the upstream program to tell it to line >> buffer explicitly > > once cat had an option -u doing exactly that but nowadays > -u seems to be ignored > > http://ww

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Wolfgang Rohdewald
On Mittwoch 11 August 2010, Cameron Simpson wrote: > Usually you either > need an option on the upstream program to tell it to line > buffer explicitly once cat had an option -u doing exactly that but nowadays -u seems to be ignored http://www.opengroup.org/onlinepubs/009695399/utilities/cat.html

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 00:11, RG wrote: | When stdin is not a tty, Python seems to buffer all the input through | EOF before processing any of it: | | [...@mickey:~]$ cat | python | print 123 | print 456 | 123 | 456 | | Is there a way to get Python to process input line-by-line the way it | does when s

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, RG wrote: > When stdin is not a tty, Python seems to buffer all the input through > EOF before processing any of it: > > [...@mickey:~]$ cat | python > print 123 > print 456 > 123 > 456 > > Is there a way to get Python to process input line-by-line the way it > does when stdin is

Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
When stdin is not a tty, Python seems to buffer all the input through EOF before processing any of it: [...@mickey:~]$ cat | python print 123 print 456 123 456 Is there a way to get Python to process input line-by-line the way it does when stdin is a TTY even when stdin is not a TTY? Thanks,