summaryrefslogtreecommitdiff
path: root/pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-05-11 14:01:18 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-05-11 14:01:18 -0700
commitee45be5723ef6001ae333110ce45ae2f7b1b17af (patch)
tree9b5e2239745395b16ba090d573c72c6ac587e9a2 /pandoc.hs
parent3800cb3d429bdcef517c84cfb8a45d2e9b85d126 (diff)
Use shell instead of proc to check for latex program.
This should get .bat files on Windows. Closes #2903, with luck.
Diffstat (limited to 'pandoc.hs')
-rw-r--r--pandoc.hs31
1 files changed, 24 insertions, 7 deletions
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