PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

System.cmd with temporary $HOME returns 126 Permission Error on macOS Sequoia

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

Marked As Solved

PJUllrich

PJUllrich

Author of Building Table Views with Phoenix LiveView

Thank you for the suggestions. I double checked the folder permissions as suggested but they looked fine. However, I found out it must be related to the java executable. I’ve recently updated asdf to the latest version which had a lot of breaking changes and I had some problems with configuring my $PATH correctly. It’s likely related to that.

# This code:
    System.cmd("java", ["--version"]) |> IO.inspect()
    System.cmd("java", ["--version"], env: [{"HOME", tmp_path}]) |> IO.inspect()

# Returns this:
{"openjdk 21.0.2 2024-01-16 LTS\nOpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)\nOpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)\n",
 0}
{"", 126} <- See how the second call returned the permission error

Edit: Yeah, it seems to be an asdf issue (issue). I’ve created a bug report here: bug: overwriting $HOME in shim command returns 126 permission error · Issue #1999 · asdf-vm/asdf · GitHub

Also Liked

derek-zhou

derek-zhou

You probably hit Gatekeeper. This is why I stop upgrading my Mac past Catalina. I might need to give up on Mac for good and go back to Linux in a couple of years, when Catalina support ends. All good things come to an end.

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement