From c6ec189a966c100a7992cc633d88efdd176c2a46 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 16 Aug 2017 10:39:34 -0700 Subject: Revision to binary format output to stdout: We now allow default output to stdout when it can be determined that the output is being piped. (On Windows, as mentioned before, this can't be determined.) Using '-o -' forces output to stdout regardless. --- src/Text/Pandoc/App.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index c7f8bbb89..367a1f550 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -91,6 +91,10 @@ import Text.Pandoc.Shared (headerShift, isURI, openURL, import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.XML (toEntities) import Text.Printf +#ifndef _WINDOWS +import System.Posix.IO (stdOutput) +import System.Posix.Terminal (queryTerminal) +#endif data LineEnding = LF | CRLF | Native deriving (Show, Generic) @@ -243,10 +247,17 @@ convertWithOpts opts = do -- We don't want to send output to the terminal if the user -- does 'pandoc -t docx input.txt'; though we allow them to - -- force this with '-o -'. - when (not (isTextFormat format) && optOutputFile opts == Nothing) $ + -- force this with '-o -'. On posix systems, we detect + -- when stdout is being piped and allow output to stdout + -- in that case, but on Windows we can't. +#ifdef _WINDOWS + let istty = True +#else + istty <- queryTerminal stdOutput +#endif + when (not (isTextFormat format) && istty && optOutputFile opts == Nothing) $ E.throwIO $ PandocAppError $ - "Cannot write " ++ format ++ " output to stdout.\n" ++ + "Cannot write " ++ format ++ " output to terminal.\n" ++ "Specify an output file using the -o option, or " ++ "use '-o -' to force output to stdout." -- cgit v1.2.3