From fc24dc1874dcf7c9e66e21502a58b40cbe627c85 Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Thu, 8 Nov 2007 00:10:28 +0100 Subject: StdinReader: exit when stdin has been closed darcs-hash:20071107231028-a5988-6787dafbed6f6c81f52989710a326e40273c2b45.gz --- Plugins/StdinReader.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Plugins/StdinReader.hs b/Plugins/StdinReader.hs index 7ad2b41..d7ec676 100644 --- a/Plugins/StdinReader.hs +++ b/Plugins/StdinReader.hs @@ -3,7 +3,7 @@ -- Module : Plugins.StdinReader -- Copyright : (c) Andrea Rossato -- License : BSD-style (see LICENSE) --- +-- -- Maintainer : Andrea Rossato -- Stability : unstable -- Portability : unportable @@ -14,13 +14,20 @@ module Plugins.StdinReader where +import Prelude hiding (catch) +import System.Posix.Process +import System.Exit import System.IO +import Control.Exception (catch) import Plugins data StdinReader = StdinReader deriving (Read, Show) -instance Exec StdinReader where +instance Exec StdinReader where start StdinReader cb = do - forever (hGetLine stdin >>= cb) - where forever a = a >> forever a + cb =<< catch (hGetLine stdin) (\e -> do hPrint stderr e; return "") + eof <- hIsEOF stdin + if eof + then exitImmediately ExitSuccess + else start StdinReader cb -- cgit v1.2.3