@@ -12,9 +12,7 @@ import Data.ByteString.Lazy (ByteString)
1212import qualified Data.ByteString.Lazy as LB
1313import System.IO (Handle, hClose, hGetContents, hPutStr,
1414 hSetEncoding, localeEncoding)
15−import System.Posix.IO (closeFd, createPipe, dupTo, fdToHandle,
16− stdInput, stdOutput)
17−import System.Posix.Process (executeFile, forkProcess)
15+import System.Process
1816
1917
2018--------------------------------------------------------------------------------
@@ -89,32 +87,19 @@ unixFilterIO :: (Handle -> i -> IO ())
8987 -> i
9088 -> IO o
9189unixFilterIO writer reader programName args input = do
92− -- Create pipes
93− (stdinRead, stdinWrite) <- createPipe
94− (stdoutRead, stdoutWrite) <- createPipe
90+ let process = (proc programName args)
91+ { std_in = CreatePipe
92+ , std_out = CreatePipe
93+ , close_fds = True
94+ }
9595
96− -- Fork the child
97− _ <- forkProcess $ do
98− -- Copy our pipes over the regular stdin/stdout
99− _ <- dupTo stdinRead stdInput
100− _ <- dupTo stdoutWrite stdOutput
101−
102− -- Close the now unneeded file descriptors in the child
103− mapM_ closeFd [stdinWrite, stdoutRead, stdinRead, stdoutWrite]
104−
105− -- Execute the program
106− _ <- executeFile programName True args Nothing
107− return ()
108−
109− -- On the parent side, close the client-side FDs.
110− mapM_ closeFd [stdinRead, stdoutWrite]
96+ (Just stdinWriteHandle, Just stdoutReadHandle, _, _) <-
97+ createProcess process
11198
11299 -- Write the input to the child pipe
113100 _ <- forkIO $ do
114− stdinWriteHandle <- fdToHandle stdinWrite
115101 writer stdinWriteHandle input
116102 hClose stdinWriteHandle
117103
118104 -- Receive the output from the child
119− stdoutReadHandle <- fdToHandle stdoutRead
120105 reader stdoutReadHandle