Problem: Windows Command line Pipe to stdin

G

GerShar

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?
 
D

Dennis Lee Bieber

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?

How to fix? First step, you drop a nuke in Washington (state); that
should get Bill Gates even if he is in his underground mansion.

Second step, you run when Linux takes over the big gap that results.


Barring all that... Try using:

....> python textGen.py | filter.py

I have vague recollections that the command shell in Windows has some
flaw when it runs an application that requires loading an interpreter
AND doing I/O redirection.
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top