git.iko.soy/typeable/pandoc
on master help sign in
Use pipeProcess in Text.Pandoc.PDF.
commit83f263110f364e87d8c0908b4a52be801aa77802 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 8 Aug 2013, 15:15 (13 years ago) parent7d694e1
1 file changed+3−36
src/Text/Pandoc/PDF.hs+3−36
src/Text/Pandoc/PDF.hs+3−36
@@ -38,11 +38,7 @@ import qualified Data.ByteString as BS
3838import System.Exit (ExitCode (..))
3939import System.FilePath
4040import System.Directory
41−import System.Process
4241import System.Environment
43−import Control.Exception (evaluate)
44−import System.IO (hClose)
45−import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
4642import Control.Monad (unless)
4743import Data.List (isInfixOf)
4844import qualified Data.ByteString.Base64 as B64
@@ -52,6 +48,8 @@ import Text.Pandoc.Generic (bottomUpM)
5248import Text.Pandoc.Shared (fetchItem, warn)
5349import Text.Pandoc.Options (WriterOptions(..))
5450import Text.Pandoc.MIME (extensionFromMimeType)
51+import Text.Pandoc.Process (pipeProcess)
52+import qualified Data.ByteString.Lazy as BL
5553
5654withTempDir :: String -> (FilePath -> IO a) -> IO a
5755withTempDir =
@@ -148,7 +146,7 @@ runTeXProgram program runsLeft tmpDir source = do
148146 $ lookup "TEXINPUTS" env'
149147 let env'' = ("TEXINPUTS", texinputs) :
150148 [(k,v) | (k,v) <- env', k /= "TEXINPUTS"]
151− (exit, out, err) <- readCommand (Just env'') program programArgs
149+ (exit, out, err) <- pipeProcess (Just env'') program programArgs BL.empty
152150 if runsLeft > 1
153151 then runTeXProgram program (runsLeft - 1) tmpDir source
154152 else do
@@ -159,34 +157,3 @@ runTeXProgram program runsLeft tmpDir source = do
159157 else return Nothing
160158 return (exit, out <> err, pdf)
161159
162−-- utility functions
163−
164−-- Run a command and return exitcode, contents of stdout, and
165−-- contents of stderr. (Based on
166−-- 'readProcessWithExitCode' from 'System.Process'.)
167−readCommand :: Maybe [(String, String)] -- ^ environment variables
168− -> FilePath -- ^ command to run
169− -> [String] -- ^ any arguments
170− -> IO (ExitCode,ByteString,ByteString) -- ^ exit, stdout, stderr
171−readCommand mbenv cmd args = do
172− (Just inh, Just outh, Just errh, pid) <-
173− createProcess (proc cmd args){ env = mbenv,
174− std_in = CreatePipe,
175− std_out = CreatePipe,
176− std_err = CreatePipe }
177− outMVar <- newEmptyMVar
178− -- fork off a thread to start consuming stdout
179− out <- B.hGetContents outh
180− _ <- forkIO $ evaluate (B.length out) >> putMVar outMVar ()
181− -- fork off a thread to start consuming stderr
182− err <- B.hGetContents errh
183− _ <- forkIO $ evaluate (B.length err) >> putMVar outMVar ()
184− -- now write and flush any input
185− hClose inh -- done with stdin
186− -- wait on the output
187− takeMVar outMVar
188− takeMVar outMVar
189− hClose outh
190− -- wait on the process
191− ex <- waitForProcess pid
192− return (ex, out, err)