blob: e286235e14b23f52c342d774016a330ac6271daa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import GHC.IO
import GHC.IO.Handle
import GHC.IO.Handle.Types
import System.IO
import Control.Concurrent.MVar
import Data.Typeable
import qualified GHC.IO.FD as FD
main = do
h <- openFile "tmp" WriteMode
hDuplicateTo h stdout
fdh <- getfd h
fdstdout <- getfd stdout
hPutStrLn stderr ("h: " ++ show (fdh /= fdstdout) ++ "\nstdout: " ++ show fdstdout)
hClose h
putStrLn "bla"
getfd h@(FileHandle _ mvar) =
withMVar mvar $ \h__@Handle__{haDevice=dev} ->
case cast dev of
Just fd -> return (FD.fdFD fd)
Nothing -> error "getfd"
|