From 69cb7f23b65f42410b5463ac6b4d87985237b4eb Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Tue, 16 Sep 2008 07:36:00 +0200 Subject: Cleaned up so that we watch the exit code darcs-hash:20080916053600-c2a52-e068e71779dd9319a450127aeb7512350f0dcc56.gz --- Plugins/CommandReader.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Plugins/CommandReader.hs b/Plugins/CommandReader.hs index fef8a45..eee23a6 100644 --- a/Plugins/CommandReader.hs +++ b/Plugins/CommandReader.hs @@ -17,7 +17,7 @@ module Plugins.CommandReader where import System.IO import Plugins -import System.Process(runInteractiveCommand) +import System.Process(runInteractiveCommand, getProcessExitCode) data CommandReader = CommandReader String String deriving (Read, Show) @@ -25,8 +25,15 @@ data CommandReader = CommandReader String String instance Exec CommandReader where alias (CommandReader _ a) = a start (CommandReader p _) cb = do - (hstdin, hstdout, hstderr, _) <- runInteractiveCommand p + (hstdin, hstdout, hstderr, ph) <- runInteractiveCommand p hClose hstdin hClose hstderr - forever (hGetLineSafe hstdout >>= cb) - where forever a = a >> forever a + hSetBinaryMode hstdout False + hSetBuffering hstdout LineBuffering + forever ph (hGetLineSafe hstdout >>= cb) + where forever ph a = + do a + ec <- getProcessExitCode ph + case ec of + Nothing -> forever ph a + Just _ -> cb "EXITED" -- cgit v1.2.3