I’m running into a 126 permission error when executing a Java command through System.cmd/3, but only if I give a custom $HOME environment variable. This problem only started recently, I think after I upgraded to macOS Sequoia, but it might also have happened before already.
Context
I have a tabula.jar executable in my priv/jars folder which I use to extract tables from PDFs. I execute it with this command:
pdf_path = "some.pdf"
tabula_path = Path.join([:code.priv_dir(:my_app), "jars", "tabula.jar"])
tmp_dir = Path.join(System.tmp_dir!(), "tabula")
result = System.cmd(
"java",
["-jar", tabula_path, "--format", "CSV", pdf_path],
env: [{"HOME", tmp_dir}]
)
case result do
{output, 0} ->
{:ok, output}
error ->
Logger.error("Failed to run Tabula: #{inspect(error)}")
{:error, "Failed to execute Tabula"}
end
The Problem
Until a few weeks ago, System.cmd/3 would return {"some-CSV-content", 0}, but now it returns {"", 126}. According to the Bash manual, an 126 exit status means:
If a command is found but is not executable, the return status is 126.
I overwrite the $HOME environment variable in the System.cmd/3 call to have Tabula store its intermediary files in a tmp folder so that I don’t have to clean it up manually. It has been that way for a year without problems, but since recently that creates the 126 permission error above because the command executes properly if I remove the env option altogether.
I double and triple checked the permissions on everything and they all have 755 permissions:
# Tmp folder in
# /var/folders/j9/515ltdpd4txcrxbc08zz4xs40000gn/T/
drwxrwxrwx@ 2 peterullrich staff 64 Feb 28 14:39 tabula
# Priv folder and Jar
drwxr-xr-x@ 11 peterullrich staff 352 Feb 28 10:46 priv
drwxr-xr-x@ 3 peterullrich staff 96 Oct 29 10:18 jars
-rwxrwxrwx@ 1 peterullrich staff 13334394 Oct 29 10:19 tabula.jar






















