@@ -91,6 +91,10 @@ import Text.Pandoc.Shared (headerShift, isURI, openURL,
91import qualified Text.Pandoc.UTF8 as UTF8
91import qualified Text.Pandoc.UTF8 as UTF8
92import Text.Pandoc.XML (toEntities)
92import Text.Pandoc.XML (toEntities)
93import Text.Printf
93import Text.Printf
95+import System.Posix.IO (stdOutput)
96+import System.Posix.Terminal (queryTerminal)
95data LineEnding = LF | CRLF | Native deriving (Show, Generic)
99data LineEnding = LF | CRLF | Native deriving (Show, Generic)
@@ -243,10 +247,17 @@ convertWithOpts opts = do
244 -- We don't want to send output to the terminal if the user
248 -- We don't want to send output to the terminal if the user
245 -- does 'pandoc -t docx input.txt'; though we allow them to
249 -- does 'pandoc -t docx input.txt'; though we allow them to
246− -- force this with '-o -'.
250+ -- force this with '-o -'. On posix systems, we detect
251+ -- when stdout is being piped and allow output to stdout
252+ -- in that case, but on Windows we can't.
256+ istty <- queryTerminal stdOutput
247− when (not (isTextFormat format) && optOutputFile opts == Nothing) $
258+ when (not (isTextFormat format) && istty && optOutputFile opts == Nothing) $
248 E.throwIO $ PandocAppError $
259 E.throwIO $ PandocAppError $
249− "Cannot write " ++ format ++ " output to stdout.\n" ++
260+ "Cannot write " ++ format ++ " output to terminal.\n" ++
250 "Specify an output file using the -o option, or " ++
261 "Specify an output file using the -o option, or " ++
251 "use '-o -' to force output to stdout."
262 "use '-o -' to force output to stdout."