process-extras-0.2.0/0000755000000000000000000000000012024743054012662 5ustar0000000000000000process-extras-0.2.0/Setup.hs0000644000000000000000000000005612024743054014317 0ustar0000000000000000import Distribution.Simple main = defaultMain process-extras-0.2.0/process-extras.cabal0000644000000000000000000000173112024743054016632 0ustar0000000000000000Name: process-extras Version: 0.2.0 Synopsis: Process extras Description: Extra functionality for the Process library . Homepage: https://github.com/davidlazar/process-extras License: MIT License-file: LICENSE Author: David Lazar, Bas van Dijk Maintainer: David Lazar Category: System Build-type: Simple Cabal-version: >=1.6 Extra-source-files: README.md source-repository head Type: git Location: https://github.com/davidlazar/process-extras Library ghc-options: -Wall Hs-source-dirs: src Exposed-modules: System.Process.ByteString System.Process.ByteString.Lazy System.Process.Text System.Process.Text.Lazy Other-modules: Utils Build-depends: base >= 4 && < 5, process, bytestring, text, deepseq process-extras-0.2.0/LICENSE0000644000000000000000000000206512024743054013672 0ustar0000000000000000Copyright (c) 2012 David Lazar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. process-extras-0.2.0/README.md0000644000000000000000000000066512024743054014150 0ustar0000000000000000# About Extra functionality for the [Process library](http://hackage.haskell.org/package/process). # Contributing This project is available on [GitHub](https://github.com/davidlazar/process-extras) and [Bitbucket](https://bitbucket.org/davidlazar/process-extras/). You may contribute changes using either. Please report bugs and feature requests using the [GitHub issue tracker](https://github.com/davidlazar/process-extras/issues). process-extras-0.2.0/src/0000755000000000000000000000000012024743054013451 5ustar0000000000000000process-extras-0.2.0/src/Utils.hs0000644000000000000000000000044012024743054015103 0ustar0000000000000000module Utils where import Control.Concurrent import Control.Exception forkWait :: IO a -> IO (IO a) forkWait a = do res <- newEmptyMVar _ <- mask $ \restore -> forkIO $ try (restore a) >>= putMVar res return (takeMVar res >>= either (\ex -> throwIO (ex :: SomeException)) return) process-extras-0.2.0/src/System/0000755000000000000000000000000012024743054014735 5ustar0000000000000000process-extras-0.2.0/src/System/Process/0000755000000000000000000000000012024743054016353 5ustar0000000000000000process-extras-0.2.0/src/System/Process/ByteString.hs0000644000000000000000000000302212024743054020776 0ustar0000000000000000module System.Process.ByteString where import Control.Exception import Control.Monad import Data.ByteString (ByteString) import qualified Data.ByteString as B import System.Process import System.Exit (ExitCode) import System.IO import Utils (forkWait) -- | Like 'System.Process.readProcessWithExitCode', but using 'ByteString' readProcessWithExitCode :: FilePath -- ^ command to run -> [String] -- ^ any arguments -> ByteString -- ^ standard input -> IO (ExitCode, ByteString, ByteString) -- ^ exitcode, stdout, stderr readProcessWithExitCode cmd args input = mask $ \restore -> do (Just inh, Just outh, Just errh, pid) <- createProcess (proc cmd args){ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe } flip onException (do hClose inh; hClose outh; hClose errh; terminateProcess pid; waitForProcess pid) $ restore $ do -- fork off a thread to start consuming stdout waitOut <- forkWait $ B.hGetContents outh -- fork off a thread to start consuming stderr waitErr <- forkWait $ B.hGetContents errh -- now write and flush any input unless (B.null input) $ do B.hPutStr inh input; hFlush inh hClose inh -- done with stdin -- wait on the output out <- waitOut err <- waitErr hClose outh hClose errh -- wait on the process ex <- waitForProcess pid return (ex, out, err) process-extras-0.2.0/src/System/Process/Text.hs0000644000000000000000000000301312024743054017630 0ustar0000000000000000module System.Process.Text where import Control.Exception import Control.Monad import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T import System.Process import System.Exit (ExitCode) import System.IO import Utils (forkWait) -- | Like 'System.Process.readProcessWithExitCode', but using 'Text' readProcessWithExitCode :: FilePath -- ^ command to run -> [String] -- ^ any arguments -> Text -- ^ standard input -> IO (ExitCode, Text, Text) -- ^ exitcode, stdout, stderr readProcessWithExitCode cmd args input = mask $ \restore -> do (Just inh, Just outh, Just errh, pid) <- createProcess (proc cmd args){ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe } flip onException (do hClose inh; hClose outh; hClose errh; terminateProcess pid; waitForProcess pid) $ restore $ do -- fork off a thread to start consuming stdout waitOut <- forkWait $ T.hGetContents outh -- fork off a thread to start consuming stderr waitErr <- forkWait $ T.hGetContents errh -- now write and flush any input unless (T.null input) $ do T.hPutStr inh input; hFlush inh hClose inh -- done with stdin -- wait on the output out <- waitOut err <- waitErr hClose outh hClose errh -- wait on the process ex <- waitForProcess pid return (ex, out, err) process-extras-0.2.0/src/System/Process/Text/0000755000000000000000000000000012024743054017277 5ustar0000000000000000process-extras-0.2.0/src/System/Process/Text/Lazy.hs0000644000000000000000000000325212024743054020554 0ustar0000000000000000module System.Process.Text.Lazy where import Control.DeepSeq (rnf) import Control.Exception import qualified Control.Exception as C (evaluate) import Control.Monad import Data.Text.Lazy (Text) import qualified Data.Text.Lazy as T import qualified Data.Text.Lazy.IO as T import System.Process import System.Exit (ExitCode) import System.IO import Utils (forkWait) -- | Like 'System.Process.readProcessWithExitCode', but using 'Text' readProcessWithExitCode :: FilePath -- ^ command to run -> [String] -- ^ any arguments -> Text -- ^ standard input -> IO (ExitCode, Text, Text) -- ^ exitcode, stdout, stderr readProcessWithExitCode cmd args input = mask $ \restore -> do (Just inh, Just outh, Just errh, pid) <- createProcess (proc cmd args){ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe } flip onException (do hClose inh; hClose outh; hClose errh; terminateProcess pid; waitForProcess pid) $ restore $ do -- fork off a thread to start consuming stdout out <- T.hGetContents outh waitOut <- forkWait $ C.evaluate $ rnf out -- fork off a thread to start consuming stderr err <- T.hGetContents errh waitErr <- forkWait $ C.evaluate $ rnf err -- now write and flush any input unless (T.null input) $ do T.hPutStr inh input; hFlush inh hClose inh -- done with stdin -- wait on the output waitOut waitErr hClose outh hClose errh -- wait on the process ex <- waitForProcess pid return (ex, out, err) process-extras-0.2.0/src/System/Process/ByteString/0000755000000000000000000000000012024743054020445 5ustar0000000000000000process-extras-0.2.0/src/System/Process/ByteString/Lazy.hs0000644000000000000000000000324412024743054021723 0ustar0000000000000000module System.Process.ByteString.Lazy where import Control.Exception import qualified Control.Exception as C (evaluate) import Control.Monad import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as B import System.Process import System.Exit (ExitCode) import System.IO import Utils (forkWait) -- | Like 'System.Process.readProcessWithExitCode', but using 'ByteString' readProcessWithExitCode :: FilePath -- ^ command to run -> [String] -- ^ any arguments -> ByteString -- ^ standard input -> IO (ExitCode, ByteString, ByteString) -- ^ exitcode, stdout, stderr readProcessWithExitCode cmd args input = mask $ \restore -> do (Just inh, Just outh, Just errh, pid) <- createProcess (proc cmd args){ std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe } flip onException (do hClose inh; hClose outh; hClose errh; terminateProcess pid; waitForProcess pid) $ restore $ do -- fork off a thread to start consuming stdout out <- B.hGetContents outh waitOut <- forkWait $ void $ C.evaluate $ B.length out -- fork off a thread to start consuming stderr err <- B.hGetContents errh waitErr <- forkWait $ void $ C.evaluate $ B.length err -- now write and flush any input unless (B.null input) $ do B.hPutStr inh input; hFlush inh hClose inh -- done with stdin -- wait on the output waitOut waitErr hClose outh hClose errh -- wait on the process ex <- waitForProcess pid return (ex, out, err)