aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/PDF.hs39
1 files changed, 3 insertions, 36 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 49b455285..b030e2ca7 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -38,11 +38,7 @@ import qualified Data.ByteString as BS
import System.Exit (ExitCode (..))
import System.FilePath
import System.Directory
-import System.Process
import System.Environment
-import Control.Exception (evaluate)
-import System.IO (hClose)
-import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
import Control.Monad (unless)
import Data.List (isInfixOf)
import qualified Data.ByteString.Base64 as B64
@@ -52,6 +48,8 @@ import Text.Pandoc.Generic (bottomUpM)
import Text.Pandoc.Shared (fetchItem, warn)
import Text.Pandoc.Options (WriterOptions(..))
import Text.Pandoc.MIME (extensionFromMimeType)
+import Text.Pandoc.Process (pipeProcess)
+import qualified Data.ByteString.Lazy as BL
withTempDir :: String -> (FilePath -> IO a) -> IO a
withTempDir =
@@ -148,7 +146,7 @@ runTeXProgram program runsLeft tmpDir source = do
$ lookup "TEXINPUTS" env'
let env'' = ("TEXINPUTS", texinputs) :
[(k,v) | (k,v) <- env', k /= "TEXINPUTS"]
- (exit, out, err) <- readCommand (Just env'') program programArgs
+ (exit, out, err) <- pipeProcess (Just env'') program programArgs BL.empty
if runsLeft > 1
then runTeXProgram program (runsLeft - 1) tmpDir source
else do
@@ -159,34 +157,3 @@ runTeXProgram program runsLeft tmpDir source = do
else return Nothing
return (exit, out <> err, pdf)
--- utility functions
-
--- Run a command and return exitcode, contents of stdout, and
--- contents of stderr. (Based on
--- 'readProcessWithExitCode' from 'System.Process'.)
-readCommand :: Maybe [(String, String)] -- ^ environment variables
- -> FilePath -- ^ command to run
- -> [String] -- ^ any arguments
- -> IO (ExitCode,ByteString,ByteString) -- ^ exit, stdout, stderr
-readCommand mbenv cmd args = do
- (Just inh, Just outh, Just errh, pid) <-
- createProcess (proc cmd args){ env = mbenv,
- std_in = CreatePipe,
- std_out = CreatePipe,
- std_err = CreatePipe }
- outMVar <- newEmptyMVar
- -- fork off a thread to start consuming stdout
- out <- B.hGetContents outh
- _ <- forkIO $ evaluate (B.length out) >> putMVar outMVar ()
- -- fork off a thread to start consuming stderr
- err <- B.hGetContents errh
- _ <- forkIO $ evaluate (B.length err) >> putMVar outMVar ()
- -- now write and flush any input
- hClose inh -- done with stdin
- -- wait on the output
- takeMVar outMVar
- takeMVar outMVar
- hClose outh
- -- wait on the process
- ex <- waitForProcess pid
- return (ex, out, err)