Search code examples
cygwinpandoc

Why does pandoc have troubles with certain paths on cygwin?


I have installed pandoc.exe 2.10 with the Windows installer, and I am calling it from cygwin 3.1.6-1. Unlike most other commands, pandoc seems to have troubles with certain paths. I get an error “openBinaryFile: does not exist (No such file or directory)” when the input or output file paths include one of the following:

  • A ~, e.g. ~/myfile.md.
  • A /cygdrive, e.g. /cygdrive/c/Users/me/myfile.md.
  • A network drive, e.g. //server/path/myfile.md.

By contrast, paths that include the following work:

  • A drive letter, e.g. c:/Users/me/myfile.md.
  • Paths relative to the current directory, e.g. ./myfile.md or simply myfile.md.
  • Network drives with backslashes, e.g. \\server\path\myfile.md.

Why is that? Why is pandoc’s behaviour different from other commands?

Most Google hits for the error message relate to R Markdown. In the JDK build-dev mailing list, the problem was related to pandoc not being a native cygwin app (see CR: 8180540: Add pandoc build fix for windows).


Solution

  • As /u/matzeri has said (thanks!), it is because Windows pandoc is a Windows program and does not recognize Cygwin path styles.

    A reliable way to fix this might be using cygpath with the --absolute and --mixed flags, like so:

    pandoc "$(cygpath -am path/to/file.md)" -o "$(cygpath -am path/to/other_file.html)"