summaryrefslogtreecommitdiffhomepage
path: root/Plugins/CommandReader.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Plugins/CommandReader.hs')
-rw-r--r--Plugins/CommandReader.hs15
1 files 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"