diff options
author | Robin Windels <rwindelz@gmail.com> | 2013-01-12 21:14:21 -0800 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-01-13 09:45:44 +0100 |
commit | f0e474ceb9ee3d9f2e5355f88ad1c73187c68e88 (patch) | |
tree | 122c0f5339cafbb514332ff638e3b7c4f96b9f53 /src/Hakyll | |
parent | 3ae0c088f22fef27bf73cbc6508e91431f970118 (diff) | |
download | hakyll-f0e474ceb9ee3d9f2e5355f88ad1c73187c68e88.tar.gz |
a unixFilter for non Posix (well windows)
Conflicts:
src/Hakyll/Core/UnixFilter.hs
Diffstat (limited to 'src/Hakyll')
-rw-r--r-- | src/Hakyll/Core/UnixFilter.hs | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/src/Hakyll/Core/UnixFilter.hs b/src/Hakyll/Core/UnixFilter.hs index dbc5e95..2a2f394 100644 --- a/src/Hakyll/Core/UnixFilter.hs +++ b/src/Hakyll/Core/UnixFilter.hs @@ -12,9 +12,7 @@ import Data.ByteString.Lazy (ByteString) import qualified Data.ByteString.Lazy as LB import System.IO (Handle, hClose, hGetContents, hPutStr, hSetEncoding, localeEncoding) -import System.Posix.IO (closeFd, createPipe, dupTo, fdToHandle, - stdInput, stdOutput) -import System.Posix.Process (executeFile, forkProcess) +import System.Process -------------------------------------------------------------------------------- @@ -89,32 +87,19 @@ unixFilterIO :: (Handle -> i -> IO ()) -> i -> IO o unixFilterIO writer reader programName args input = do - -- Create pipes - (stdinRead, stdinWrite) <- createPipe - (stdoutRead, stdoutWrite) <- createPipe + let process = (proc programName args) + { std_in = CreatePipe + , std_out = CreatePipe + , close_fds = True + } - -- Fork the child - _ <- forkProcess $ do - -- Copy our pipes over the regular stdin/stdout - _ <- dupTo stdinRead stdInput - _ <- dupTo stdoutWrite stdOutput - - -- Close the now unneeded file descriptors in the child - mapM_ closeFd [stdinWrite, stdoutRead, stdinRead, stdoutWrite] - - -- Execute the program - _ <- executeFile programName True args Nothing - return () - - -- On the parent side, close the client-side FDs. - mapM_ closeFd [stdinRead, stdoutWrite] + (Just stdinWriteHandle, Just stdoutReadHandle, _, _) <- + createProcess process -- Write the input to the child pipe _ <- forkIO $ do - stdinWriteHandle <- fdToHandle stdinWrite writer stdinWriteHandle input hClose stdinWriteHandle -- Receive the output from the child - stdoutReadHandle <- fdToHandle stdoutRead reader stdoutReadHandle |