read from standard input

Jaroslav Jákl j.jakl at era.cz
Mon Aug 12 02:03:03 EDT 2002


Thank you for your help,
I tried just script.py < file (on win 2000).
python script.py < file works right.
Regards,
Jaroslav Jakl


"Bengt Richter" <bokr at oz.net> pí¹e v diskusním pøíspìvku
news:aj7aer$9t$0 at 216.39.172.122...
> On Fri, 9 Aug 2002 16:04:31 +0200, "Jaroslav Jákl" <j.jakl at era.cz> wrote:
>
> >Hi all,
> >I want to read from stdin. I have the following script:
> >
> >import sys
> >for line in sys.stdin.readlines():
> >    print line
> >
> >and if i execute it like script.py < file, i get IOError: [Errno 9] Bad
file
> >descriptor.
> >Can anybody advise me?
> >thanks
> >Jaroslav Jakl
> >
> You are apparently on windows? Try running python explicitly. The thing
created by
> automatic data file extension to run an app doesn't do i/o redirection
properly.
> E.g., this is on NT4 with python 2.2
>
>  [20:40] C:\pywk\junk>type script.py
>  import sys
>  for line in sys.stdin.readlines():
>      print line
>
>  [20:41] C:\pywk\junk>echo test.txt >test.txt
>
>  [20:41] C:\pywk\junk>script.py < test.txt
>  Traceback (most recent call last):
>    File "C:\pywk\junk\script.py", line 2, in ?
>      for line in sys.stdin.readlines():
>  IOError: [Errno 9] Bad file descriptor
>
>  [20:42] C:\pywk\junk>python script.py < test.txt
>  test.txt
>
> Regards,
> Bengt Richter





More information about the Python-list mailing list