how to access a DOS env variable from java

I need to access a DOS Environment variable such as %ENV1% from a java application.
LVL 1
WinDudeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

loumfCommented:
java.lang.System.getenv()
0
WinDudeAuthor Commented:
Ya, tried this... I must be doing it wrong.

Got an example?
0
loumfCommented:
When you call it don't use the % signs on the variable.  Try to call it with "path" and you get the path.  Otherwise it should just work
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

AMD_MANCommented:

The getenv() method is depreciated as of Java 1.1:

"This method is obsolete; it always throws an error. Use getProperties() and the -D option instead."
- Java Language Reference

Use getProperties() to get all of the properties, then getProperty(key) where key is the variable you want to get.

You can also use the -D option on the command line to override/add variables to the mix...

Later,
AMD_MAN
0
WinDudeAuthor Commented:
By the way, getenv() is Deprecated to getProperty().

It seems I can get plenty of java environment info, but nothing from the DOS environment.  If I open a dos window and type SET and hit enter I get a list of environment variables.  This list does not come though a call to getenv() or getProperty().  Any other ideas?
0
WinDudeAuthor Commented:
I tried getPropert("LOGONSERVER"); and it retuned a 'null' so it needs more work.  LOGONSERVER when I type SET is in the env.
0
AMD_MANCommented:

WinDude,

     You may have to abandon getting the environment variables that way.  I ran a program to view the properties and ran into the same problem you did.

     After some additional research, I think I know why Java doesn't rely on what you "set".  In order to keep java platform independent, they seem to have dropped any use of a particular OS environment except for things like CLASSPATH.  What I have seen instead is the use of properties files in Java.  Or use of the command line.  Is it possible for you to go that route?

Best of luck,
AMD_MAN
0
WinDudeAuthor Commented:
I was using properties files and ini files and that was working great, but then I was asked to try for the dos environment variable and ran into the brick wall there.

Thanks for trying though :)
0
AMD_MANCommented:

If you can find a solution, please post it!  I would love to know.  If not, feel free to accept my comment as an answer.  That way others can get to it in the database, and maybe avoid environment problems...

AMD_MAN
0
Ravindra76Commented:


HI,

It is a answer of paq  in this iste told by some other expert

You can define environment variables and in the java program you can access the value also.
Do like this:
First set environment variable
like this
set DMV_HOME=jdbc:odbc:mysource
And then in the prorgam you can the value of this environment variable like this
String dmvhome=System.getProperty("DMV_HOME");
But when you run the program you have to pass the environment variable to the program
using -D option
java -DDMV_HOME="%DMV_HOME%" GetProperty
Assume that my program name is GetProperty.java;

Best of luck

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbormannCommented:
use 'C' code to get the environment vars,and call n set a static method in ur Java class using JNI .

that is the only clean way of doing it,if u want the whole code i will post it here if u requewst that.
0
mbormannCommented:
>>>>>that is the only clean way of doing it

and portable ,will work everywhere,in all Unix's, i am not sure abt Mac/linux.
remember,Java is meant to be portable.
0
WinDudeAuthor Commented:
the commandline -D option worked great.  JNI probably works too, but I think there might be some performance issues going that route.

Thanks to all!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.