0

I am setting the value an env. variable (say runOnEnv) in my terminal as:

export runOnEnv=dev 

But when I am trying t access it in my java code like:

String envVarValue = System.getenv("runOnEnv"); 

The value of this comes out to be null.

Am I missing something? If not how can this be done ?

2
  • Surely System.getenv( "runOnEnv" )? Commented Jan 28, 2014 at 13:24
  • @SurajMenon - Would you care to share what was wrong? I am in similar situation Commented Jan 4, 2017 at 6:34

1 Answer 1

1

I'm sure you mean System.getenv( "runOnEnv" ) -- including hyphens.

Are you running your Java program in the same shell as the export ...? You should be aware that export makes the variable available to the process and subprocesses, not parent processes - thus it won't be available in another shell.

Hope that helps.

Cheers,

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.