[IronPython] IronPython and file descriptors

Curt Hagenlocher curt at hagenlocher.org
Mon Dec 15 18:28:04 CET 2008

There's no such thing as a file descriptor number in .NET -- or, for that
matter, in Windows itself! :)  (The latter is something of a semantic point,
of course, as a HANDLE serves something of the same role in Win32 as a file
descriptor number does in Unix.)
If you have a FileStream, I think you can turn it into a Windows HANDLE by
IntPtr handle = stream.SafeFileHandle.DangerousGetHandle();
The C library should have a way to convert a HANDLE into a "file
descriptor", though I wasn't able to identify the function name with a quick
I don't see a way to get handles for stdin, stdout or stderr, though, except
that these ought to be easy to translate by hand.

 On Mon, Dec 15, 2008 at 8:03 AM, Tom Wright <tom.wright at resolversystems.com
> wrote:

> Hi,
> At the moment file.fileno() returns an arbitrary identifier of a python
> file rather than a true file descriptor. This is semi-blocking the Ironclad
> port of PIL.
> Code in PIL gets an integer using fileno() and passes it directly to C code
> where a call to write() is made. To fix this  one would have to patch PIL,
> IronPython's file objects or the write function provided to C code - none of
> these feel like a good course of action.
> When ctypes is ported to IronPython this may create similar problems.
> Ideally fileno() would return a real file descriptor. Would this be
> possible?
> Thanks,
> Tom
> Resolver Systems
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081215/1bb887d4/attachment.html>

More information about the Ironpython-users mailing list