git.iko.soy/typeable/pandoc
on master help sign in
Revision to binary format output to stdout:
c6ec189John MacFarlane
MANUAL.txt+4−3
@@ -109,9 +109,10 @@ Using `pandoc`
109If no *input-file* is specified, input is read from *stdin*.
109If no *input-file* is specified, input is read from *stdin*.
110Otherwise, the *input-files* are concatenated (with a blank
110Otherwise, the *input-files* are concatenated (with a blank
111line between each) and used as input. Output goes to *stdout* by
111line between each) and used as input. Output goes to *stdout* by
112−default (though output to *stdout* is disabled for the `odt`, `docx`,
112+default (though output to the terminal is disabled for the
113−`epub2`, and `epub3` output formats, unless it is forced using
113+`odt`, `docx`, `epub2`, and `epub3` output formats, unless it is
114−`-o -`). For output to a file, use the `-o` option:
114+forced using `-o -`). For output to a file, use the `-o`
115+option:
115
116
116 pandoc -o output.html input.txt
117 pandoc -o output.html input.txt
117
118
src/Text/Pandoc/App.hs+14−3
@@ -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
94+#ifndef _WINDOWS
95+import System.Posix.IO (stdOutput)
96+import System.Posix.Terminal (queryTerminal)
97+#endif
94
98
95data LineEnding = LF | CRLF | Native deriving (Show, Generic)
99data LineEnding = LF | CRLF | Native deriving (Show, Generic)
96
100
@@ -243,10 +247,17 @@ convertWithOpts opts = do
243
247
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.
253+#ifdef _WINDOWS
254+ let istty = True
255+#else
256+ istty <- queryTerminal stdOutput
257+#endif
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."
252
263