git.iko.soy/typeable/pandoc
on master help sign in
Use shell instead of proc to check for latex program.

This should get .bat files on Windows. Closes #2903, with luck.

commitee45be5723ef6001ae333110ce45ae2f7b1b17af authorJohn MacFarlane <jgm@berkeley.edu> dateWed 11 May 2016, 14:01 (10 years ago) parent3800cb3
1 file changed+24−7
pandoc.hs+24−7
pandoc.hs+24−7
@@ -52,8 +52,9 @@ import Data.Char ( toLower, toUpper )
5252import Data.List ( delete, intercalate, isPrefixOf, isSuffixOf, sort )
5353import System.Directory ( getAppUserDataDirectory, findExecutable,
5454 doesFileExist, Permissions(..), getPermissions )
55−import System.Process ( readProcessWithExitCode )
56−import System.IO ( stdout, stderr )
55+import System.Process ( shell, CreateProcess(..), createProcess_,
56+ waitForProcess, StdStream(CreatePipe) )
57+import System.IO ( stdout, stderr, hClose )
5758import System.IO.Error ( isDoesNotExistError )
5859import qualified Control.Exception as E
5960import Control.Exception.Extensible ( throwIO )
@@ -1402,11 +1403,8 @@ convertWithOpts opts args = do
14021403 _ | html5Output -> "wkhtmltopdf"
14031404 _ -> latexEngine
14041405 -- check for pdf creating program
1405− (ec,_,_) <- E.catch
1406− (readProcessWithExitCode pdfprog ["--version"] "")
1407− (\(_ :: E.SomeException) ->
1408− return (ExitFailure 1,"",""))
1409− when (ec /= ExitSuccess) $
1406+ progExists <- checkProg pdfprog
1407+ when (not progExists) $
14101408 err 41 $ pdfprog ++ " not found. " ++
14111409 pdfprog ++ " is needed for pdf output."
14121410
@@ -1428,3 +1426,22 @@ convertWithOpts opts args = do
14281426 handleEntities = if htmlFormat && ascii
14291427 then toEntities
14301428 else id
1429+
1430+-- Check for existence of prog by doing prog --version.
1431+checkProg :: String -> IO Bool
1432+checkProg "" = return False
1433+checkProg prog = E.handle handleErr $ do
1434+ (_,Just o,Just e,p) <- createProcess_ "system"
1435+ (shell (prog ++ " --version")){
1436+ delegate_ctlc = True,
1437+ std_out = CreatePipe,
1438+ std_err = CreatePipe
1439+ }
1440+ ec <- waitForProcess p
1441+ hClose o
1442+ hClose e
1443+ if ec == ExitSuccess
1444+ then return True
1445+ else return False
1446+ where handleErr :: E.SomeException -> IO Bool
1447+ handleErr _ = return False