`withBinaryFile: invalid argument (Invalid argument)` error
I'm trying to track down the cause of a withBinaryFile: invalid argument (Invalid argument) error I'm seeing with pandoc on Windows... any idea what causes it, in general? (There aren't many hits after searching for a while.) Appreciate any insight you might have. Thanks!
There aren't any references to this error in pandoc's own code, and a few adjacent hits in issues, it appears that withBinaryFile and invalid argument are inherent to Haskell ( https://hoogle.haskell.org/?hoogle=withBinaryFile )? (I have zero exp in Haskell btw.)
Admittedly, I'm also kinda doing something weird, but maybe these details help (?)... I'm running something like pandoc file.md -o file.docx on Windows with the latest pandoc version 3.1.9 and it works flawlessly in either PowerShell or Git Bash... also running sh -c 'pandoc file.md -o file.docx' in Git Bash works fine... but if I run from within a Rust utility in Git Bash via std::process::Command::new("sh").args(["-c", "pandoc file.md -o file.docx"]).spawn().unwrap().wait().unwrap() suddenly it doesn't work... but other commands that don't use pandoc via this method work fine.
I have also tried several other Pandoc versions and so far they're all consistently working / not working in the same way.
I've also tried various contents of the input markdown file ranging from very complex (>6000 lines with hundreds of images, divs with custom styles, and with/without --reference-doc=reference.dox) to a super basic input markdown with a level 1 heading and a single paragraph. No matter what (so far) I get: pandoc.exe: file.md: withBinaryFile: invalid argument (Invalid argument).
I'm guessing there's either some permissions issue and/or a file path issue stemming from a windows/git-bash inconsistency.
See also: https://github.com/JessicaTegner/pypandoc/issues/292#issuecomment-1802403378
That's really strange. I don't actually know what triggers InvalidArgument IO exception. I've never seen that before. Are symlinks involved?
Honestly, this situation is pretty weird... so I'd imagine it probably doesn't affect many people. Regardless, I do like to document such things in case anyone else sees this (or myself again in ~6 months), it's documented here.
There's definitely no direct symlinks that I'm using on purpose in these files. I have tried both with local folders and files in the current directory and seems to have no effect.
I'm planning to try a few more ideas as well as investigate more around how Rust's std::process::Command works on Windows, since that's probably the next weakest point in my knowledge (after Haskell). Will report back if/when I figure it out. Thanks again!
Does rust have a version of the process command that separates out the arguments instead of just passing in a big string with the full command? If so, try that?
Does rust have a version of the process command that separates out the arguments instead of just passing in a big string with the full command? If so, try that?
No effect; same error
Here's an example of the output from Rust utility (mkrs) with contents of file.rst just hello and the following tweaks:
```text
$ pandoc -v
c = "pandoc" "-v"
pandoc 3.1.8
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: C:\Users\qtfkwk\AppData\Roaming\pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
```
```text
$ pandoc file.rst -t markdown
c = "pandoc" "file.rst" "-t" "markdown"
pandoc: file.rst: withBinaryFile: invalid argument (Invalid argument)
```
fn run(command: &str, dry_run: bool) {
bunt::println!("{$#555555}```text\n${/$} {$#00ffff+bold}{}{/$}", command);
+ /*
if !dry_run
- && std::process::Command::new("sh")
+ && !std::process::Command::new("sh")
.args(["-c", command])
.spawn()
.unwrap()
.wait()
.unwrap()
- .code()
- != Some(0)
+ .success()
{
bunt::println!("{$#555555}```{/$}\n");
error!(4, "ERROR: The command failed!");
}
+ */
+ if !dry_run {
+ let mut c = execute::command(command);
+ eprintln!("c = {c:?}");
+ if !c.spawn().unwrap().wait().unwrap().success() {
+ bunt::println!("{$#555555}```{/$}\n");
+ error!(4, "ERROR: The command failed!");
+ }
+ }
bunt::println!("{$#555555}```{/$}\n");
}
is the problem finished? I'm faced with it also and cannot find the reason.I'm windows too and my ob version is 1.5.3
I was facing this problem in python:
subprocess.run(["pandoc", f"{file}", f"-o {export_file_path.as_posix()}", "--pdf-engine=xelatex"])
This does the trick:
subprocess.run(["pandoc", f"{file}", "-o", f"{export_file_path.as_posix()}", "--pdf-engine=xelatex"])
Notice the "-o" is split from the filepath. I have no idea why not doing so leads to this error. I suspect the rust issue is something similar.
Cool. Will check. Thanks!
The difference is that your first command is effectively running:
pandoc "$file" "-o $export_file_path" --pdf-engine=xelatex
Instead of:
pandoc "$file" -o "$export_file_path" --pdf-engine=xelatex
So I presume the whatever pandoc uses for command line option/argument parsing, or Haskell itself, is choking on the "-o $export_file_path" argument.
Correct. Can this issue now be closed?