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.
This commit is contained in:
John MacFarlane 2017-08-16 10:39:34 -07:00
parent cf4b40162d
commit c6ec189a96
2 changed files with 18 additions and 6 deletions

View file

@ -109,9 +109,10 @@ Using `pandoc`
If no *input-file* is specified, input is read from *stdin*.
Otherwise, the *input-files* are concatenated (with a blank
line between each) and used as input. Output goes to *stdout* by
default (though output to *stdout* is disabled for the `odt`, `docx`,
`epub2`, and `epub3` output formats, unless it is forced using
`-o -`). For output to a file, use the `-o` option:
default (though output to the terminal is disabled for the
`odt`, `docx`, `epub2`, and `epub3` output formats, unless it is
forced using `-o -`). For output to a file, use the `-o`
option:
pandoc -o output.html input.txt

View file

@ -91,6 +91,10 @@ import Text.Pandoc.Shared (headerShift, isURI, openURL,
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.XML (toEntities)
import Text.Printf
#ifndef _WINDOWS
import System.Posix.IO (stdOutput)
import System.Posix.Terminal (queryTerminal)
#endif
data LineEnding = LF | CRLF | Native deriving (Show, Generic)
@ -243,10 +247,17 @@ convertWithOpts opts = do
-- We don't want to send output to the terminal if the user
-- does 'pandoc -t docx input.txt'; though we allow them to
-- force this with '-o -'.
when (not (isTextFormat format) && optOutputFile opts == Nothing) $
-- force this with '-o -'. On posix systems, we detect
-- when stdout is being piped and allow output to stdout
-- in that case, but on Windows we can't.
#ifdef _WINDOWS
let istty = True
#else
istty <- queryTerminal stdOutput
#endif
when (not (isTextFormat format) && istty && optOutputFile opts == Nothing) $
E.throwIO $ PandocAppError $
"Cannot write " ++ format ++ " output to stdout.\n" ++
"Cannot write " ++ format ++ " output to terminal.\n" ++
"Specify an output file using the -o option, or " ++
"use '-o -' to force output to stdout."