@@ -91,10 +91,6 @@ 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
9894
9995data LineEnding = LF | CRLF | Native deriving (Show, Generic)
10096
@@ -124,7 +120,7 @@ parseOptions options' defaults = do
124120convertWithOpts :: Opt -> IO ()
125121convertWithOpts opts = do
126122 let args = optInputFiles opts
127− let outputFile = optOutputFile opts
123+ let outputFile = fromMaybe "-" (optOutputFile opts)
128124 let filters = optFilters opts
129125 let verbosity = optVerbosity opts
130126
@@ -245,18 +241,14 @@ convertWithOpts opts = do
245241 (\(syn,dep) -> (T.unpack syn ++ " requires " ++
246242 T.unpack dep ++ " through IncludeRules.")) xs)
247243
248−
249−
250−#ifdef _WINDOWS
251− let istty = True
252−#else
253− istty <- queryTerminal stdOutput
254−#endif
255− when (istty && not (isTextFormat format) && outputFile == "-") $
244+ -- 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
246+ -- force this with '-o -'.
247+ when (not (isTextFormat format) && optOutputFile opts == Nothing) $
256248 E.throwIO $ PandocAppError $
257249 "Cannot write " ++ format ++ " output to stdout.\n" ++
258− "Specify an output file using the -o option."
259−
250+ "Specify an output file using the -o option, or " ++
251+ "use '-o -' to force output to stdout."
260252
261253 let convertTabs = tabFilter (if optPreserveTabs opts || readerName == "t2t"
262254 then 0
@@ -303,7 +295,8 @@ convertWithOpts opts = do
303295 variables <-
304296 withList (addStringAsVariable "sourcefile")
305297 (reverse $ optInputFiles opts)
306− (("outputfile", optOutputFile opts) : optVariables opts)
298+ (("outputfile", fromMaybe "-" (optOutputFile opts))
299+ : optVariables opts)
307300 -- we reverse this list because, unlike
308301 -- the other option lists here, it is
309302 -- not reversed when parsed from CLI arguments.
@@ -562,7 +555,7 @@ data Opt = Opt
562555 , optTemplate :: Maybe FilePath -- ^ Custom template
563556 , optVariables :: [(String,String)] -- ^ Template variables to set
564557 , optMetadata :: [(String, String)] -- ^ Metadata fields to set
565− , optOutputFile :: FilePath -- ^ Name of output file
558+ , optOutputFile :: Maybe FilePath -- ^ Name of output file
566559 , optInputFiles :: [FilePath] -- ^ Names of input files
567560 , optNumberSections :: Bool -- ^ Number sections in LaTeX
568561 , optNumberOffset :: [Int] -- ^ Starting number for sections
@@ -638,7 +631,7 @@ defaultOpts = Opt
638631 , optTemplate = Nothing
639632 , optVariables = []
640633 , optMetadata = []
641− , optOutputFile = "-" -- "-" means stdout
634+ , optOutputFile = Nothing
642635 , optInputFiles = []
643636 , optNumberSections = False
644637 , optNumberOffset = [0,0,0,0,0,0]
@@ -889,7 +882,7 @@ options =
889882
890883 , Option "o" ["output"]
891884 (ReqArg
892− (\arg opt -> return opt { optOutputFile = arg })
885+ (\arg opt -> return opt { optOutputFile = Just arg })
893886 "FILE")
894887 "" -- "Name of output file"
895888