diff options
author | James Crayne <jim.crayne@gmail.com> | 2016-04-27 15:20:53 -0400 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2016-04-27 15:32:46 -0400 |
commit | 6260d694a99348bc474b87b3d2184ead70cf3511 (patch) | |
tree | 1481e2c37dc136a1f3ebe4d8c2c25536ea85b8a9 /lib/ProcessUtils.hs | |
parent | 39c085fff40fcb2dfea17d1d8b20b1387ff1e2af (diff) |
new testcase: cokiki ssh-client
Diffstat (limited to 'lib/ProcessUtils.hs')
-rw-r--r-- | lib/ProcessUtils.hs | 19 |
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 | ||
8 | import GHC.IO.Exception ( ioException, IOErrorType(..) ) | 9 | import GHC.IO.Exception ( ioException, IOErrorType(..) ) |
@@ -14,6 +15,8 @@ import Data.Maybe ( isNothing ) | |||
14 | import System.IO.Error ( mkIOError, ioeSetErrorString ) | 15 | import System.IO.Error ( mkIOError, ioeSetErrorString ) |
15 | import System.Exit ( ExitCode(..) ) | 16 | import System.Exit ( ExitCode(..) ) |
16 | import System.IO | 17 | import System.IO |
18 | import Control.Applicative | ||
19 | import 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 | |||
91 | readProcessWithErrorH :: FilePath -> [String] -> String -> Handle -> IO String | ||
92 | readProcessWithErrorH 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 ) | ||