Problem: Windows Command line Pipe to stdin

GerShar gerryandsharon at sympatico.ca
Sun Oct 30 16:40:10 EST 2005


Python 2.3 on Windows XP



The following works when run from the command line.



import sys

text = sys.stdin.read()
# do something on the text
# ...
sys.stdout.write(text)



But if the above code is used as a filter program that gets another programs 
output as shown below, it fails as shown.



C:\>textGen.py |  filter.py

Traceback (most recent call last):

  File "C:\filter.py", line 4, in ?

    text = sys.stdin.read()

IOError: [Errno 9] Bad file descriptor



Any ideas on what is happening and how to fix it?





More information about the Python-list mailing list