I want to create a annonymous pipe on windows using the CreatePipe
of the WinAPI via the FFI. This will give me a HANDLE
(type from the Win32
haskell package), but I'd like to get an ordinary haskell Handle
such that I can use the standard haskell IO functions on it. So I need a function of type:
win32handleToStandardHandle :: HANDLE -> IO Handle
How can I implement this?
On linux, I can use System.Posix.IO
's fdToHandle
function to convert between the FD
type used by the linux system calls and the standard haskell type. But there seems to be no such function for windows.
Even on Windows the standard implementation of files in System.IO
uses a file descriptor, not a win32 HANDLE
. These file descriptors are provided by the C runtime, not Windows. To convert a HANDLE
to a file descriptor the runtime provides the _open_osfhandle
function. GHC uses MinGW on Windows but MinGW doesn't provide its own C runtime, so Haskell EXEs use msvcrt.dll.
Use the FFI to import _open_osfhandle
. Use this to convert your HANDLE
to a file descriptor and then call fdToHandle
, which seems to live in GHC.IO.Handle.FD
.
I haven't actually tried this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With