Newsgroups: comp.lang.python
From: "Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu>
Date: Tue, 3 Dec 2002 20:56:31 -0600
Local: Wed 4 Dec 2002 02:56
Subject: Weirdness with python and stdin redirection under Win32
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" Consider the following script, which I want to use as a prototype for a # foo.py print "fileno = ", sys.stdin.fileno() lines = sys.stdin.xreadlines() On win32 (Win2k pro, SP3), using ActiveState ActivePython 2.2.1 build 222, I If I type "echo bar | foo.py", I get C:\>echo bar | foo.py whereas if I type "echo bar | python foo.py", I get C:\>echo bar | python foo.py Other tests yield: C:\>foo.py < foo.py C:\>python foo.py < foo.py print "fileno = ", sys.stdin.fileno() lines = sys.stdin.xreadlines() If I just type "foo.py" or "python foo.py" on the command line, I get Can anyone explain what's happening? Why the file descriptor for redirected Thanks, You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: b...@oz.net (Bengt Richter)
Date: 4 Dec 2002 05:24:54 GMT
Local: Wed 4 Dec 2002 05:24
Subject: Re: Weirdness with python and stdin redirection under Win32
On Tue, 3 Dec 2002 20:56:31 -0600, "Jonathan M. Gilligan" <jonathan.gilli...@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" You have bumped into a well-known bug present in many but not all versions A number of versions of windows do not correctly set up for redirected i/o The workaround is to invoke the interpreter explicitly, as in python foo.py There should be a FAQ by now, I would think. Regards, You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: Piet van Oostrum <p...@cs.uu.nl>
Date: 04 Dec 2002 13:53:59 +0100
Local: Wed 4 Dec 2002 12:53
Subject: Re: Weirdness with python and stdin redirection under Win32
BR> On Tue, 3 Dec 2002 20:56:31 -0600, "Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu> wrote:
>> I am getting an error reading stdin only when I invoke a python script by BR> [...] >> 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> You have bumped into a well-known bug present in many but not all versions BR> A number of versions of windows do not correctly set up for redirected i/o BR> The workaround is to invoke the interpreter explicitly, as in python foo.py There are also Windows versions where batch files have that same bug!! You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: Piet van Oostrum <p...@cs.uu.nl>
Date: 04 Dec 2002 13:56:19 +0100
Local: Wed 4 Dec 2002 12:56
Subject: Re: Weirdness with python and stdin redirection under Win32
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. PvO> There are also Windows versions where batch files have that same bug!! I would like to add that a good solution is to use a special program like You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: b...@oz.net (Bengt Richter)
Date: 4 Dec 2002 19:03:39 GMT
Local: Wed 4 Dec 2002 19:03
Subject: Re: Weirdness with python and stdin redirection under Win32
On 04 Dec 2002 13:53:59 +0100, Piet van Oostrum <p...@cs.uu.nl> wrote:
Ick. I didn't know that ;-/ Can you mention a specific example? Regards, You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: Piet van Oostrum <p...@cs.uu.nl>
Date: 04 Dec 2002 22:07:33 +0100
Local: Wed 4 Dec 2002 21:07
Subject: Re: Weirdness with python and stdin redirection under Win32
BR> On 04 Dec 2002 13:53:59 +0100, Piet van Oostrum <p...@cs.uu.nl> wrote:
BR> On Tue, 3 Dec 2002 20:56:31 -0600, "Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu> wrote: >>>> I am getting an error reading stdin only when I invoke a python script by BR> You have bumped into a well-known bug present in many but not all versions >>>> 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> of windows. 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> (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!! BR> Can you mention a specific example? E.g. on Windows 98, make a file test1.bat, containing just: and then run from a command prompt: The output just goes to your screen, and the file out will be empty. You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: Norbert.Klam...@klamann-software.de (Norbert Klamann)
Date: 4 Dec 2002 03:25:57 -0800
Local: Wed 4 Dec 2002 11:25
Subject: Re: Weirdness with python and stdin redirection under Win32
"Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu> wrote in message <news:asjset$n3l$1@news.vanderbilt.edu>...
> I am getting an error reading stdin only when I invoke a python script by [nearly everything snipped] > 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" > Can anyone explain what's happening? Why the file descriptor for redirected If I remember correctly this is a Windows bug, it was mentioned sometimes on this > stdin has a fileno of -1 if the python script is invoked using "foo.py" but > not when it's invoked with "python foo.py"? > Thanks, list. HTH Norbert Klamann You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: Thomas Heller <thel...@python.net>
Date: 04 Dec 2002 13:29:54 +0100
Local: Wed 4 Dec 2002 12:29
Subject: Re: Weirdness with python and stdin redirection under Win32
Norbert.Klam...@klamann-software.de (Norbert Klamann) writes: Right, but it is fixed in Win2k (and hopefully also on XP). > "Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu> wrote in message <news:asjset$n3l$1@news.vanderbilt.edu>... > > I am getting an error reading stdin only when I invoke a python script by > If I remember correctly this is a Windows bug, it was mentioned sometimes on this Thomas You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: Tim Roberts <t...@probo.com>
Date: Thu, 05 Dec 2002 23:19:36 -0800
Local: Fri 6 Dec 2002 07:19
Subject: Re: Weirdness with python and stdin redirection under Win32
Thomas Heller <thel...@python.net> wrote: I'm afraid not. The bug certainly DOES exist in Win2K, and I suspect it >Norbert.Klam...@klamann-software.de (Norbert Klamann) writes: >> "Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu> wrote in message <news:asjset$n3l$1@news.vanderbilt.edu>... >> > I am getting an error reading stdin only when I invoke a python script by >> If I remember correctly this is a Windows bug, it was mentioned sometimes on this >Right, but it is fixed in Win2k (and hopefully also on XP). also exists in XP. -- - Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
Newsgroups: comp.lang.python
From: "Jonathan M. Gilligan" <jonathan.gilli...@vanderbilt.edu>
Date: Wed, 4 Dec 2002 11:15:49 -0600
Local: Wed 4 Dec 2002 17:15
Subject: Re: Weirdness with python and stdin redirection under Win32
The bug is NOT fixed in Win2k. That's where I am seeing it (Win2K Pro SP3).
Jonathan You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
| Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy |
| ©2009 Google |