beardedeagle

beardedeagle

I’m trying to figure out how to be able to expand ENV variables in either Port or System.cmd. Porcelain seems to be capable of this, but I cannot do it with either Port or System.cmd:

iex(5)> System.cmd("/bin/echo", ["$GOPATH"])
{"$GOPATH\n", 0}
iex(6)> port = Port.open({:spawn_executable, "/bin/echo"}, [:binary, args: ["$GOPATH"]])
#Port<0.10>
iex(7)> flush()
{#Port<0.10>, {:data, "$GOPATH\n"}}
:ok
Porcelain.shell("echo $GOPATH")
%Porcelain.Result{err: nil, out: "/Users/rlthompson/go\n", status: 0}

The issue is Porcelain is in a state where I am uncomfortable using it in production (it’s basically abandonware in my personal opinion). I tried taking a look at how Porcelain is accomplishing this, but was unable to make heads or tails of the specific calls they make.

Any help, direction or docs to be pointed at would be greatly appreciated. Thank you in advance.

Showing Posts 1 to 10

lpil

lpil

Creator of Gleam

What makes you say this? It’s a well defined library that could be considered complete. It’s not like the *nix CLI is a moving target that the library needs to be updated to work with :slight_smile:

beardedeagle

beardedeagle OP

That’s just my personal opinion. I’m uncomfortable using it in production for what it the app I would use it in does. This also isn’t just for *nix, the app I would use this in is cross platform. I’m not going to use Porcelain, which is why I’m trying to figure out how to do it with System.cmd or Ports.

beardedeagle

beardedeagle OP

Also, it’s a matter of getting this past management as well. I can tell you right now my managers wouldn’t approve the use of a library that isn’t actively kept up.

isaacsanders

isaacsanders

If you look at the documentation for opening ports in the erlang library, you will find an env option. That is where you would set the environment. You might just have to pass the current environment there to add the options you want.

beardedeagle

beardedeagle OP

@isaacsanders I saw that in the otp docs and in the elixir Ports docs, but that doesn’t look it’s usable for existing env variables, just for passing a env variable at the time of opening the port. I could be wrong though.

isaacsanders

isaacsanders

Also, I would advise just using the underlying port infrastructure in Erlang’s and Elixir’s standard libraries if Porcelain makes you uncomfortable.

isaacsanders

isaacsanders

If you are trying to get a subset of your environment sent to the port, I would do so explicitly. I am under the impression from what you have posted that it doesn’t look at parameters in your shell, but requires you to set the env for the shell it creates.

beardedeagle

beardedeagle OP

@isaacsanders so if I’m understanding you correctly you mean this?:

iex(11)> System.cmd("/bin/echo", ["$GOPATH"], env: [{"$GOPATH", "/Users/rlthompson/go"}])
{"$GOPATH\n", 0}

However that doesn’t appear to work either.

isaacsanders

isaacsanders

Try:

iex(2)> System.cmd("env", [], env: [{"GOPATH", "/Users/rlthompson/go"}])

This shows that it exists in the env.

I think that to get further, you might need a shell script around it.

I tried:

System.cmd("/bin/echo", ["$GOPATH"], env: [{"GOPATH", "/Users/rlthompson/go"}])

and

System.cmd("/bin/echo $GOPATH", [], env: [{"GOPATH", "/Users/rlthompson/go"}])

Neither giving a desired result.

isaacsanders

isaacsanders

This works:

iex(1)> System.cmd("sh", ["test.sh"], env: [{"GOPATH", "/Users/rlthompson/go"}])
{"/Users/rlthompson/go\n", 0}

test.sh:

echo $GOPATH

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

HR_Sportograf
Backend Developer for Elixir (F/M/D) - Shape the Future of Sports Photography with Us!(German Version below) About us We are athletes –...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews