Getting the file descriptor of a handle, without closing it

2012-03-10 Thread Volker Wysk
Hello! A few months ago, I started a discussion about how to extract the file descriptor of a handle, without the side effect of closing the handle. Bas van Dijk kindly provided the following function: unsafeWithHandleFd :: Handle -> (Fd -> IO a) -> IO a (The action in the second argument is a

Re: Getting the file descriptor of a handle, without closing it

2012-03-10 Thread Volker Wysk
Hi This is an addition to my previous post. This modified version of main seems to work: main = do fd <- unsafeWithHandleFd stdin return putStrLn ("stdin: fd = " ++ show fd) fd <- unsafeWithHandleFd stdout return putStrLn ("stdout: fd = " ++ show fd) The way I understand it,

Re: Getting the file descriptor of a handle, without closing it

2012-03-10 Thread John Meacham
Can you use 'dup' to copy the file descriptor and return that version? That will keep a reference to the file even if haskell closes the original descriptor. John On Sat, Mar 10, 2012 at 5:31 PM, Volker Wysk wrote: > Hi > > This is an addition to my previous post. > > > This modified versio

Re: Getting the file descriptor of a handle, without closing it

2012-03-12 Thread Simon Marlow
On 11/03/2012 01:31, Volker Wysk wrote: Hi This is an addition to my previous post. This modified version of main seems to work: main = do fd<- unsafeWithHandleFd stdin return putStrLn ("stdin: fd = " ++ show fd) fd<- unsafeWithHandleFd stdout return putStrLn ("stdout: fd =

Re: Getting the file descriptor of a handle, without closing it

2012-03-12 Thread Volker Wysk
Am Montag 12 März 2012, 12:31:27 schrieb Simon Marlow: > On 11/03/2012 01:31, Volker Wysk wrote: > > However, I want to use it with stdin, stdout and stderr, only. > > Is there some reason you can't just use 0, 1, and 2? This is complicated. I want to be able to fork a child action, and communica