aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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