reading piped input in Windows

Patrick Useldinger p at trick.lu
Sat Nov 15 12:27:22 EST 2003


Hi,
I am writing a filter, i.e. a program that reads from stdin and writes
to stdout. It works ok when run on its own, but does not work when I try
to use another program's output.

-  The producer program (t1):
print "a b c"
print "d e f"

- The filter program (t2):
import sys
r = sys.stdin.readlines()
for i in r:
    print '<',i,'>'

When i connect them using 't1 ¦ t2', I get the following error message:
Traceback (most recent call last):
  File "[...]", line 2, in ?
    r = sys.stdin.readlines()
IOError: [Errno 9] Bad file descriptor

The same programs work correctly under Linux, so I suppose that Windows
handles redirectionned input differently from 'normal' console input.
Can anyone point me to a portable solution that works both under Windows
and Linux?

-PU




More information about the Python-list mailing list