?
Solved

how to access a DOS env variable from java

Posted on 2000-01-26
13
Medium Priority
?
620 Views
Last Modified: 2006-11-17
I need to access a DOS Environment variable such as %ENV1% from a java application.
0
Comment
Question by:WinDude
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 1

Expert Comment

by:loumf
ID: 2390067
java.lang.System.getenv()
0
 
LVL 1

Author Comment

by:WinDude
ID: 2390099
Ya, tried this... I must be doing it wrong.

Got an example?
0
 
LVL 1

Expert Comment

by:loumf
ID: 2390142
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Expert Comment

by:AMD_MAN
ID: 2390161

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
 
LVL 1

Author Comment

by:WinDude
ID: 2390212
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
 
LVL 1

Author Comment

by:WinDude
ID: 2390223
I tried getPropert("LOGONSERVER"); and it retuned a 'null' so it needs more work.  LOGONSERVER when I type SET is in the env.
0
 

Expert Comment

by:AMD_MAN
ID: 2390311

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
 
LVL 1

Author Comment

by:WinDude
ID: 2390594
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
 

Expert Comment

by:AMD_MAN
ID: 2390993

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
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 200 total points
ID: 2391755


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
 
LVL 5

Expert Comment

by:mbormann
ID: 2392124
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
 
LVL 5

Expert Comment

by:mbormann
ID: 2392150
>>>>>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
 
LVL 1

Author Comment

by:WinDude
ID: 2394290
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

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month4 days, 5 hours left to enroll

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question