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

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement