fileinput.input() fails on Windows 2K

Tim Roberts timr at probo.com
Tue Apr 30 01:26:18 EDT 2002


"Ingo Blank" <spam at yourself.com> wrote:
>
>this tiny script gives a traceback under Windows 2K if/when input is piped
>in to stdin, while it runs as expected under Linux.
>
>## MakeDef.py
>## Read ouput of DUMPBIN /EXPORTS <file.DLL> and create a .DEF file
>
>from string import *
>import fileinput
>
>print "EXPORTS"
>hit = 0
>for line in fileinput.input():
> words = split(line)
> if hit and len(words) == 4:
>  print "\t%s" % words[3]
> hit |= find(line,"RVA") >= 0
>
>----------------
>
>C:>DUMPBIN /EXPORTS libjpeg.dll | MakeDEF.py
>
>Traceback (most recent call last):
>  File "C:\MakeDEF.py", line 6, in ?
>    for line in fileinput.input():
>  File "E:\Python21\lib\fileinput.py", line 181, in __getitem__
>    line = self.readline()
>  File "E:\Python21\lib\fileinput.py", line 262, in readline
>    self._buffer = self._file.readlines(self._bufsize)
>IOError: [Errno 9] Bad file descriptor
>
>-----------------
>
>Am I missing something, or is this a bug in fileinput.py ?
>I'm using ActiveState Python 2.1.

It is a known bug, apparently in the Windows 2000 shell itself.  You can
work around the problem by invoking Python instead of relying on the .py
extension:

C:>DUMPBIN /EXPORTS libjpeg.dll | python MakeDEF.py

You can use popen from inside MakeDEF.py to invoke the DUMPBIN command and
parse the output, if you want.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list