@@ -91,6 +91,10 @@ import Text.Pandoc.Shared (headerShift, isURI, openURL,
9191import qualified Text.Pandoc.UTF8 as UTF8
9292import Text.Pandoc.XML (toEntities)
9393import Text.Printf
94+#ifndef _WINDOWS
95+import System.Posix.IO (stdOutput)
96+import System.Posix.Terminal (queryTerminal)
97+#endif
9498
9599data LineEnding = LF | CRLF | Native deriving (Show, Generic)
96100
@@ -243,10 +247,17 @@ convertWithOpts opts = do
243247
244248 -- We don't want to send output to the terminal if the user
245249 -- does 'pandoc -t docx input.txt'; though we allow them to
246− -- force this with '-o -'.
247− when (not (isTextFormat format) && optOutputFile opts == Nothing) $
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.
253+#ifdef _WINDOWS
254+ let istty = True
255+#else
256+ istty <- queryTerminal stdOutput
257+#endif
258+ when (not (isTextFormat format) && istty && optOutputFile opts == Nothing) $
248259 E.throwIO $ PandocAppError $
249− "Cannot write " ++ format ++ " output to stdout.\n" ++
260+ "Cannot write " ++ format ++ " output to terminal.\n" ++
250261 "Specify an output file using the -o option, or " ++
251262 "use '-o -' to force output to stdout."
252263