aspose file tools*
The moose likes Java in General and the fly likes Creating an environment variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating an environment variable" Watch "Creating an environment variable" New topic
Author

Creating an environment variable

Pete Dawn
Greenhorn

Joined: Sep 28, 2006
Posts: 17
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

Joined: Dec 31, 2004
Posts: 961
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating an environment variable
 
Similar Threads
Using Java Virtual Machine
environment variable
Problem with setting up environment variable
getting and setting environment variables
JBoss JNDI question - very basic