[Tutor] execute an OS command, get the output

Terry Carroll carroll at tjc.com
Sun Mar 12 04:32:13 CET 2006


On Sat, 11 Mar 2006, Terry Carroll wrote:

> Just for the heack of it, I wrote a tiny Python echo program, and 
> interposed it in the pipe between the strings and grep command:
> 
>  while 1:
>      line = raw_input()
>      print line
> 
> The command line now looks like this:
> 
>  strings 00003193.DAT | python echo.py | grep Newsgroups: | head

Actually, to break it down to its simplest, with the python program:

 for i in range(1,10000):
     print "line", i

I get:

> writeabunch.py | head -5
line 1
line 2
line 3
line 4
line 5
Traceback (most recent call last):
  File "C:\Agent-files\Giganews\writeabunch.py", line 2, in ?
    print "line", i
IOError: (0, 'Error')
close failed: [Errno 22] Invalid argument

Same thing, but a far simpler scenario.

Interestingly, if I use a low enough range, say range(1,500), it simply 
runs to completion; I assume that 500 lines in the form of "line n\n" fit 
within the first written buffer.




More information about the Tutor mailing list