Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating an environment variable

 
Pete Dawn
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys and gals,

i am trying to create some environment variables from within my java app.

now i have two probs,
1. how should i create a environment variable from within my app.
2. how should i edit the environment variable value.

now what i have done is, i have created the environment variable manually from withing My Computer and then tried to edit it. i am able to retreive the value and even edit it but surprisingly when i go back to my computer to check the new value, its still the old value.

Properties p = ReadEnv.getEnvVars();
String varLoc = p.getProperty(TEST_VAR);

so my question is how can i edit it in such a way that its reflected in my computer too.

and second question, how can i create an environment variable and even delete it if needed.

thanks.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Pete.

I think the best way (if not the only) is to use a java.lang.ProcessBuilder.

For instance, I just did an example.bat file that contains:



Since the environment variable MY_NAME is not defined, I will have to define it before calling the example.bat.

The way to do it is this:



You will see how the batch file uses the variable that you defined.

Does this help you somehow?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic