Reading from stdin (in windows)
rtw at freenet.co.uk
Tue Oct 14 13:43:01 CEST 2008
durumdara at gmail.com wrote in news:mailman.2448.1223974725.3487.python-
list at python.org in comp.lang.python:
> I wanna write a file processor in python (Windows XP).
> I wanna use pipe, and not parameters.
> When I write this:
> l = 
> while 1:
> t = sys.stdin.read(1)
> if t == '':
> t = "".join(l)
> and use code this:
> process.py <test.txt
> I got:
> "Bad file descriptor"
> What I do wrong? I need to call this module in another format?
> Or I read in wrong way?
The problem appear to be that MS-Windows doesn't make pipe's for
programs it opens via its file type association mechanism.
Essentially MS-Windows is treating the .py file as a document and
using python to "open" the document.
Try running you program as:
python process.py <test.txt
Note for this to work python will have to be on your path. If
it isn't use the full path to you copy of python. for e.g.:
c:\python25\python.exe process.py <test.txt
More information about the Python-list