summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ProcessUtils.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/ProcessUtils.hs b/lib/ProcessUtils.hs
index 06f6893..a6902be 100644
--- a/lib/ProcessUtils.hs
+++ b/lib/ProcessUtils.hs
@@ -3,6 +3,7 @@ module ProcessUtils
3 ( ExitCode(ExitFailure,ExitSuccess) 3 ( ExitCode(ExitFailure,ExitSuccess)
4 , systemEnv 4 , systemEnv
5 , readPipe 5 , readPipe
6 , readProcessWithErrorH
6 ) where 7 ) where
7 8
8import GHC.IO.Exception ( ioException, IOErrorType(..) ) 9import GHC.IO.Exception ( ioException, IOErrorType(..) )
@@ -14,6 +15,8 @@ import Data.Maybe ( isNothing )
14import System.IO.Error ( mkIOError, ioeSetErrorString ) 15import System.IO.Error ( mkIOError, ioeSetErrorString )
15import System.Exit ( ExitCode(..) ) 16import System.Exit ( ExitCode(..) )
16import System.IO 17import System.IO
18import Control.Applicative
19import Control.Exception (bracket)
17 20
18 21
19-- | systemEnv 22-- | systemEnv
@@ -83,3 +86,19 @@ readPipe ((cmd,args):xs) stdin0 = do
83 (Nothing,Just sout,Just serr, ph) <- createProcess p 86 (Nothing,Just sout,Just serr, ph) <- createProcess p
84 readPipe0 xs sout 87 readPipe0 xs sout
85 readPipe0 [] h = hGetContents h 88 readPipe0 [] h = hGetContents h
89
90
91readProcessWithErrorH :: FilePath -> [String] -> String -> Handle -> IO String
92readProcessWithErrorH cmd args stdin erH = do
93 let p = (shell cmd) { std_in = CreatePipe
94 , std_out = CreatePipe
95 , std_err = UseHandle erH
96 , cmdspec = RawCommand cmd args
97 }
98 bracket (createProcess p)
99 (\(Just sinh,Just sout,_, ph) ->
100 mapM_ hClose [sinh,sout] )
101 (\(Just sinh,Just sout,_, ph) -> do
102 hPutStr sinh stdin
103 hClose sinh
104 hGetContents sout )