Solved

getProperty?

Posted on 2001-08-29
6
369 Views
Last Modified: 2008-03-17
When I type "set" at the command prompt, I see:
SystemDrive=C:

In a Java program, I do
System.getProperty("SystemDrive");
I get nothing.

How do I do this? (getting "SystemDrive"?)

Thanks.
0
Comment
Question by:samliam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Veroland
ID: 6437082
you have to run your java program with the system property flag i.e.
c:\java yourapp -DSystemDrive=C:

0
 
LVL 2

Expert Comment

by:Veroland
ID: 6437089
the flag is the -D
0
 

Author Comment

by:samliam
ID: 6437244
My question is:
How do I get system information such as SystemDrive or any other environment variables I have set in a DOS box?

For example, to get the OS, I can do System.getProperty("os.name"); However, this does not work for other environment variables including "SystemDrive".
0
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 7

Accepted Solution

by:
Igor Bazarny earned 20 total points
ID: 6437266
...And -D should go before class name, like:
c:\java -DSystemDrive=C: yourapp

In fact, java doesn't let you access environment variables, so you need to take care about passing them to your code yourself. Another option would be use of Runtime.exec():

Runtime r = Runtime.getRuntime();
Process p = Runtime.exec("command /c set");
InputStream envStream = p.getInputStream();
// parse envStream to get all environment variables

This approach is not portable--on Windows NT/2000 command interpreter called cmd, and more differences for unix--different command interpreter, different command to list environment variables. Mac didn't support environment variables at all (I guess FreeBSD-based OS X supports them)

Regards,
Igor Bazarny,
Brainbench MVP for Java 1
www.brainbench.com

0
 

Author Comment

by:samliam
ID: 6438088
Veroland,
I'll post 20 points for you separately.

Thank you both.
0
 

Author Comment

by:samliam
ID: 6438167
btw,

what if I already have e.g.,

ARG="..... a very long string"

How do I use the '-D' flag:

java -DARG=%ARG% my_app??

this does not work...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

728 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