Using environment variables with ports

In this previous post here, the poster asks the same question I have. I cannot seem to get the syntax correct in order to launch a Port with environment variables.

The solution shows how to do it using System.cmd, but I need a port because I need to manage the pid and this executable will be running for a long time. The erlang syntax is also in the original post, but I need to know how to do this in Elixir.

The Elixir code that I have that does not work (gives me “bad argument”) is as follows:

host_info = HostCore.Host.generate_hostinfo_for(public_key)
port ={:spawn, "#{path}"}, [:binary, {:env, [{'WASMCLOUD_HOST_DATA', host_info}]}] )

Where host_info is just a Jason encoded string.

Based on the typespecs in the erlang docs this needs to be a charlist not a binary.

1 Like

Ugh, I can’t believe that was the bad argument and it wasn’t some other syntax thing. I was convinced I was screwing up the keyword list syntax.


Erlang functions often take what is called proplists, which are lists of either atoms, or {atom, value} tuples like elixir keyword lists have.