@@ -74,6 +74,10 @@ import Text.Pandoc.Readers.Txt2Tags (getT2TMeta)
7474import Paths_pandoc (getDataDir)
7575import Text.Printf (printf)
7676import Text.Pandoc.Error
77+#ifndef _WINDOWS
78+import System.Posix.Terminal (queryTerminal)
79+import System.Posix.IO (stdOutput)
80+#endif
7781
7882type Transform = Pandoc -> Pandoc
7983
@@ -1357,7 +1361,12 @@ convertWithOpts opts args = do
13571361 , readerFileScope = fileScope
13581362 }
13591363
1360− when (not (isTextFormat format) && outputFile == "-") $
1364+#ifdef _WINDOWS
1365+ let istty = True
1366+#else
1367+ istty <- queryTerminal stdOutput
1368+#endif
1369+ when (istty && not (isTextFormat format) && outputFile == "-") $
13611370 err 5 $ "Cannot write " ++ format ++ " output to stdout.\n" ++
13621371 "Specify an output file using the -o option."
13631372
@@ -1457,8 +1466,9 @@ convertWithOpts opts args = do
14571466 applyTransforms transforms >=>
14581467 applyFilters datadir filters' [format]) doc
14591468
1460− let writeBinary :: B.ByteString -> IO ()
1461− writeBinary = B.writeFile (UTF8.encodePath outputFile)
1469+ let writeFnBinary :: FilePath -> B.ByteString -> IO ()
1470+ writeFnBinary "-" = B.putStr
1471+ writeFnBinary f = B.writeFile (UTF8.encodePath f)
14621472
14631473 let writerFn :: FilePath -> String -> IO ()
14641474 writerFn "-" = UTF8.putStr
@@ -1466,7 +1476,7 @@ convertWithOpts opts args = do
14661476
14671477 case writer of
14681478 IOStringWriter f -> f writerOptions doc' >>= writerFn outputFile
1469− IOByteStringWriter f -> f writerOptions doc' >>= writeBinary
1479+ IOByteStringWriter f -> f writerOptions doc' >>= writeFnBinary outputFile
14701480 PureStringWriter f
14711481 | pdfOutput -> do
14721482 -- make sure writer is latex or beamer or context or html5
@@ -1486,7 +1496,7 @@ convertWithOpts opts args = do
14861496
14871497 res <- makePDF pdfprog f writerOptions doc'
14881498 case res of
1489− Right pdf -> writeBinary pdf
1499+ Right pdf -> writeFnBinary outputFile pdf
14901500 Left err' -> do
14911501 B.hPutStr stderr err'
14921502 B.hPut stderr $ B.pack [10]