By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Problem: Windows Command line Pipe to stdin

P: n/a
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?
Oct 30 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Sun, 30 Oct 2005 16:40:10 -0500, "GerShar"
<ge************@sympatico.ca> declaimed the following in
comp.lang.python:
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.
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Oct 31 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.