From 455b75246e1af3c71f21dc3ba7fa4030f9346606 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Tue, 16 Sep 2008 07:20:25 +0200 Subject: Added CommandReader darcs-hash:20080916052025-c2a52-b56fb3901980591a17383a9267166cc3c9d34185.gz --- Plugins/CommandReader.hs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Plugins/CommandReader.hs (limited to 'Plugins') 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 +-- 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 -- cgit v1.2.3