We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Clearing inherited variables in System.cmd
almirsarajcic
0 comments
Copy link
Passing env: [] to System.cmd/3 does not clear the child environment.
System.put_env("VENDOR_TOKEN", "development")
System.cmd("sh", ["-c", ~s(printf %s "$VENDOR_TOKEN")], env: [])
#=> {"development", 0}
System.cmd("sh", ["-c", ~s(printf %s "$VENDOR_TOKEN")],
env: [{"VENDOR_TOKEN", nil}]
)
#=> {"", 0}
The child inherits its parent environment. :env changes only the keys you provide, so an empty list leaves it alone.
Use nil for a token or other value that must not reach a subprocess. Otherwise, a local credential can make a test or external command succeed by accident.
copied to clipboard