git.iko.soy/typeable/pandoc
on master help sign in
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.

commitc6ec189a966c100a7992cc633d88efdd176c2a46 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 16 Aug 2017, 10:39 (9 years ago) parentcf4b401
2 files changed+18−6
MANUAL.txt+4−3 src/Text/Pandoc/App.hs+14−3
MANUAL.txt+4−3
@@ -109,9 +109,10 @@ Using `pandoc`
109109If no *input-file* is specified, input is read from *stdin*.
110110Otherwise, the *input-files* are concatenated (with a blank
111111line between each) and used as input. Output goes to *stdout* by
112−default (though output to *stdout* is disabled for the `odt`, `docx`,
113−`epub2`, and `epub3` output formats, unless it is forced using
114−`-o -`). For output to a file, use the `-o` option:
112+default (though output to the terminal is disabled for the
113+`odt`, `docx`, `epub2`, and `epub3` output formats, unless it is
114+forced using `-o -`). For output to a file, use the `-o`
115+option:
115116
116117 pandoc -o output.html input.txt
117118
src/Text/Pandoc/App.hs+14−3
@@ -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