diff options
Diffstat (limited to 'Plugins')
| -rw-r--r-- | Plugins/CommandReader.hs | 31 | 
1 files changed, 31 insertions, 0 deletions
| diff --git a/Plugins/CommandReader.hs b/Plugins/CommandReader.hs new file mode 100644 index 0000000..b084aba --- /dev/null +++ b/Plugins/CommandReader.hs @@ -0,0 +1,31 @@ +----------------------------------------------------------------------------- +-- | +-- Module      :  Plugins.CommandReader +-- Copyright   :  (c) John Goerzen +-- License     :  BSD-style (see LICENSE) +-- +-- Maintainer  :  Andrea Rossato <andrea.rossato@unibz.it> +-- Stability   :  unstable +-- Portability :  unportable +-- +-- A plugin for reading from external commands +-- note: stderr is lost here +-- +----------------------------------------------------------------------------- + +module Plugins.CommandReader where + +import System.IO +import Plugins + +data CommandReader = CommandReader String String +    deriving (Read, Show) + +instance Exec CommandReader where +    alias (CommandReader _ a)    = a +    start (CommandReader p _) cb = do +        (hstdin, hstdout, hstderr) <- runInteractiveCommand p +        hClose hstdin +        hClose hstderr +        forever (hGetLineSafe hstdout >>= cb) +        where forever a = a >> forever a | 
