propellor spin

This commit is contained in:
Joey Hess 2014-05-11 10:22:59 -03:00
parent 43a23578eb
commit f92800ad0f
Failed to extract signature
1 changed files with 7 additions and 0 deletions

View File

@ -35,9 +35,11 @@ simpleSh namedpipe = do
maybe noop (run h) . readish =<< hGetLine h
where
run h (Cmd cmd params) = do
debug ["simplesh run", cmd, show params]
chan <- newChan
let runwriter = do
v <- readChan chan
debug ["simplesh run", cmd, show params, "writer got:", show v]
hPutStrLn h (show v)
hFlush h
case v of
@ -52,6 +54,7 @@ simpleSh namedpipe = do
, std_err = CreatePipe
}
(Nothing, Just outh, Just errh, pid) <- createProcess p
debug ["simplesh run", cmd, show params, "started"]
let mkreader t from = maybe noop (const $ mkreader t from)
=<< catchMaybeIO (writeChan chan . t =<< hGetLine from)
@ -59,15 +62,19 @@ simpleSh namedpipe = do
(mkreader StdoutLine outh)
(mkreader StderrLine errh)
debug ["simplesh run", cmd, show params, "waiting for process"]
void $ tryIO $ waitForProcess pid
debug ["simplesh run", cmd, show params, "sending Done"]
writeChan chan Done
hClose outh
hClose errh
debug ["simplesh run", cmd, show params, "wait writer"]
wait writer
hClose h
debug ["simplesh run", cmd, show params, "fully done"]
simpleShClient :: FilePath -> String -> [String] -> ([Resp] -> IO a) -> IO a
simpleShClient namedpipe cmd params handler = do