From fd0f8c1a8a03cedf868ea2b26e40bfe00852d0b2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 18 Jul 2013 21:51:23 -0700 Subject: Text.Pandoc.PDF: put temporary output directory in TEXINPUTS. This will help later when we try to download external resources. We can put them in the temp directory. See #917. --- src/Text/Pandoc/PDF.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs index 3227fd0bd..b36f2a0af 100644 --- a/src/Text/Pandoc/PDF.hs +++ b/src/Text/Pandoc/PDF.hs @@ -38,6 +38,7 @@ 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) @@ -102,7 +103,12 @@ runTeXProgram program runsLeft tmpDir source = do unless exists $ UTF8.writeFile file source let programArgs = ["-halt-on-error", "-interaction", "nonstopmode", "-output-directory", tmpDir, file] - (exit, out, err) <- readCommand program programArgs + env' <- getEnvironment + let texinputs = maybe (tmpDir ++ ":") ((tmpDir ++ ":") ++) + $ lookup "TEXINPUTS" env' + let env'' = ("TEXINPUTS", texinputs) : + [(k,v) | (k,v) <- env', k /= "TEXINPUTS"] + (exit, out, err) <- readCommand (Just env'') program programArgs if runsLeft > 1 then runTeXProgram program (runsLeft - 1) tmpDir source else do @@ -118,12 +124,14 @@ runTeXProgram program runsLeft tmpDir source = do -- Run a command and return exitcode, contents of stdout, and -- contents of stderr. (Based on -- 'readProcessWithExitCode' from 'System.Process'.) -readCommand :: FilePath -- ^ command to run +readCommand :: Maybe [(String, String)] -- ^ environment variables + -> FilePath -- ^ command to run -> [String] -- ^ any arguments -> IO (ExitCode,ByteString,ByteString) -- ^ exit, stdout, stderr -readCommand cmd args = do +readCommand mbenv cmd args = do (Just inh, Just outh, Just errh, pid) <- - createProcess (proc cmd args){ std_in = CreatePipe, + createProcess (proc cmd args){ env = mbenv, + std_in = CreatePipe, std_out = CreatePipe, std_err = CreatePipe } outMVar <- newEmptyMVar -- cgit v1.2.3