Getting :enoent on System.cmd() but file exists (deployed on

Hi guys,

I deployed a small LiveView app on but when I try to upload an image and run System.cmd() on it, it returns :enoent which should indicate that the file doesn’t exists, but it does, the function checks if ti exists and I also checked manually using iex console.

def content_type(filepath) do
    with true <- File.exists?(filepath),
         {file_utility_output, 0} <- System.cmd("file", ["--mime", "--brief", filepath])
      content_type =
      {:ok, content_type}
      {error, 1} ->
        {:error, error}

      false ->

Path example


Trying to run it manually from iex

filepath  = "/uploads/tmp/live_view_upload-1710842554-413969956620-1.png"
iex(...)6> File.exists?(filepath)
iex(...)7> dbg System.cmd("file", ["--mime", "--brief", filepath])
** (ErlangError) Erlang error: :enoent
    (elixir 1.16.0) lib/system.ex:1101: System.cmd("file", ["--mime", "--brief", filepath], [])
    iex:7: (file)

Do you have any idea what could cause this behaviour?

Solved it, I had to add file package to my Dockerfile.

Which library did you add?

It’s just called file

this is the line inside Dockerfile, I added file to it

RUN apt-get update -y && \
  apt-get install -y libstdc++6 openssl libncurses5 locales file ca-certificates \
  && apt-get clean && rm -f /var/lib/apt/lists/*_*
1 Like