Weirdness with python and stdin redirection under Win32

Piet van Oostrum piet at cs.uu.nl
Wed Dec 4 07:53:59 EST 2002


>>>>> 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!!
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum at hccnet.nl



More information about the Python-list mailing list