2 % (c) The GRASP/AQUA Project, Glasgow University, 1995
4 \section[LibPosix]{Haskell 1.3 POSIX bindings}
38 import LibPosixProcEnv
39 import LibPosixProcPrim
43 -- runProcess is our candidate for the high-level OS-independent primitive
44 -- If accepted, it will be moved out of LibPosix into LibSystem.
46 import LibDirectory ( setCurrentDirectory )
49 import PreludePrimIO ( takeMVar, putMVar, _MVar )
52 runProcess :: FilePath -- Command
53 -> [String] -- Arguments
54 -> Maybe [(String, String)] -- Environment
55 -> Maybe FilePath -- Working directory
56 -> Maybe Handle -- stdin
57 -> Maybe Handle -- stdout
58 -> Maybe Handle -- stderr
60 runProcess path args env dir stdin stdout stderr =
61 forkProcess >>= \ pid ->
63 Nothing -> doTheBusiness
66 doTheBusiness :: IO ()
68 maybeChangeWorkingDirectory >>
72 executeFile path True args env >>
75 maybeChangeWorkingDirectory :: IO ()
76 maybeChangeWorkingDirectory =
79 Just x -> setCurrentDirectory x
81 maybeDup2 :: Int -> Maybe Handle -> IO ()
83 case h of Nothing -> return ()
84 Just x -> handleFD x >>= \ src ->
85 dupChannelTo src dest >>
88 handleFD :: Handle -> IO Channel
90 takeMVar handle >>= \ htype ->
91 putMVar handle htype >>
93 _ErrorHandle ioError -> failWith ioError
94 _ClosedHandle -> failWith (IllegalOperation "handle is closed")
95 _SemiClosedHandle _ _ -> failWith (IllegalOperation "handle is closed")
97 _casm_ ``%r = fileno((FILE *)%0);'' (_filePtr other)