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:
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.
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
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.
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.
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.
@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.
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.
Hrm. Maybe I just need to dig even deeper into how Porcelain is pulling this off because their shell/2 command can do this without the use of a script. good tip on the script though. Ideally my users would be grabbing env variables in their check and handler plugins rather than trying to pass them in the check command they are doing. (I know, no context. Sorry)
Correct. This app is a monitoring service where they can create checks and a part of the check is the path to the check plugin and opts to pass to it. So allowing them to do as much as possible is the goal.