Weirdness with python and stdin redirection under Win32

Bengt Richter bokr at oz.net
Wed Dec 4 14:03:39 EST 2002


On 04 Dec 2002 13:53:59 +0100, Piet van Oostrum <piet at cs.uu.nl> wrote:

>>>>>> bokr at oz.net (Bengt Richter) (BR) writes:
>
>BR> On Tue, 3 Dec 2002 20:56:31 -0600, "Jonathan M. Gilligan" <jonathan.gilligan at vanderbilt.edu> wrote:
>>> I am getting an error reading stdin only when I invoke a python script by
>>> typing "bar | foo.py" or "foo.py < bar", but not when typing "bar | python
>>> foo.py" or "python foo.py < bar". The error arises ecause when input is
>>> redirected, stdin has fileno = -1 if the script is invoked as "foo.py", but
>>> correctly has fileno = 0 if it is invoked as "python foo.py"
>>> 
>BR> [...]
>
>BR> You have bumped into a well-known bug present in many but not all versions
>BR> of windows.
>
>BR> A number of versions of windows do not correctly set up for redirected i/o
>BR> when a script is run based on running an interpreter selected by automatic
>BR> association via the script's file extension. This will affect e.g., perl also.
>
>BR> The workaround is to invoke the interpreter explicitly, as in python foo.py
>BR> (as you did) or to put that in a .cmd or .bat file and then use that file
>BR> as the executable, and redirect i/o wrt to that.
>
>There are also Windows versions where batch files have that same bug!!
Ick. I didn't know that ;-/
Can you mention a specific example?

Regards,
Bengt Richter



More information about the Python-list mailing list