[Tutor] Strange XP stdin behaviour.

Alan Gauld ukc802591034 at btconnect.com
Sat Aug 27 02:33:52 CEST 2005


Hi gang, a strange one uncovered by a student of my tutorial.

If you create the following example program, lets call it intest.py:

####### intest.py #####
inp = raw_input()
while inp != '':
   print inp
   inp = raw_input()
#######################

And the following data file

-------- Not part of in.txt -----
6
7
8

-------- Not part of in.txt -----

Then run Python from a DOS prompt like so:

C:\somepath> pythopn intest.py < in.txt

The file content is echo'd as expected.

But if you start it:

C:\somepath> intest.py < in.txt

There is no output! 
In fact, I get an error:

E:\PROJECTS\Python>intest.py < in.txt
Traceback (most recent call last):
  File "E:\PROJECTS\Python\intest.py", line 2, in ?
    inp = raw_input()
EOFError: EOF when reading a line

And if you run

C:\somepath> intest.py

You get the interactive version as expected.

Why the difference with the redirected file? I am confused.
What am I missing? XP seems to have a different runtime 
environment depending on how the script is run... 
BTW This also happens under cygwin.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050827/05554dc4/attachment.htm


More information about the Tutor mailing list