From ee45be5723ef6001ae333110ce45ae2f7b1b17af Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 11 May 2016 14:01:18 -0700 Subject: Use shell instead of proc to check for latex program. This should get .bat files on Windows. Closes #2903, with luck. --- pandoc.hs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'pandoc.hs') diff --git a/pandoc.hs b/pandoc.hs index 76803be43..7a2a38d39 100644 --- a/pandoc.hs +++ b/pandoc.hs @@ -52,8 +52,9 @@ import Data.Char ( toLower, toUpper ) import Data.List ( delete, intercalate, isPrefixOf, isSuffixOf, sort ) import System.Directory ( getAppUserDataDirectory, findExecutable, doesFileExist, Permissions(..), getPermissions ) -import System.Process ( readProcessWithExitCode ) -import System.IO ( stdout, stderr ) +import System.Process ( shell, CreateProcess(..), createProcess_, + waitForProcess, StdStream(CreatePipe) ) +import System.IO ( stdout, stderr, hClose ) import System.IO.Error ( isDoesNotExistError ) import qualified Control.Exception as E import Control.Exception.Extensible ( throwIO ) @@ -1402,11 +1403,8 @@ convertWithOpts opts args = do _ | html5Output -> "wkhtmltopdf" _ -> latexEngine -- check for pdf creating program - (ec,_,_) <- E.catch - (readProcessWithExitCode pdfprog ["--version"] "") - (\(_ :: E.SomeException) -> - return (ExitFailure 1,"","")) - when (ec /= ExitSuccess) $ + progExists <- checkProg pdfprog + when (not progExists) $ err 41 $ pdfprog ++ " not found. " ++ pdfprog ++ " is needed for pdf output." @@ -1428,3 +1426,22 @@ convertWithOpts opts args = do handleEntities = if htmlFormat && ascii then toEntities else id + +-- Check for existence of prog by doing prog --version. +checkProg :: String -> IO Bool +checkProg "" = return False +checkProg prog = E.handle handleErr $ do + (_,Just o,Just e,p) <- createProcess_ "system" + (shell (prog ++ " --version")){ + delegate_ctlc = True, + std_out = CreatePipe, + std_err = CreatePipe + } + ec <- waitForProcess p + hClose o + hClose e + if ec == ExitSuccess + then return True + else return False + where handleErr :: E.SomeException -> IO Bool + handleErr _ = return False -- cgit v1.2.3