Home > Blockchain >  System.getenv() not showing last added environment variables
System.getenv() not showing last added environment variables

Time:01-03

I want to access to some environment variables that I set on .bashrc but i cannot get it using System.getenv(), I am using Intellij-idea ultimate on Ubuntu Linux.

On .bashrc i have:

export TWILIO_SMS_SERVICE_SID="XXXXXXXXXX"
export TWILIO_ACCOUNT_SID="XXXXXXXXXX"
export TWILIO_AUTH_TOKEN="XXXXXXXXXX"

Running on command line $ echo $TWILIO_SMS_SERVICE_SID i got the correct value XXXXXXXXXX.

But this System.getenv("TWILIO_SMS_SERVICE_SID") returns null.

When i run this, i got all the environment variables but not the last that i added:

println("Environment variables: ")
System.getenv().forEach { (key, value) -> println("$key: $value") }

Do you know what the causes might be or how to fix it?

p.s: sorry, I have no idea how to do a POC about this, I am open to any suggestion.

CodePudding user response:

Did you start the Java program directly from IntelliJ IDEA? Depending on how you started it, it might not have the environment variables set, as ~/.bashrc might only be evaluated when you start a bash shell. It should work if you start IntelliJ IDEA (or just your Java program) from the bash shell that has the environment variables set.

  • Related