?
Solved

getProperty?

Posted on 2001-08-29
6
Medium Priority
?
373 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 7

Accepted Solution

by:
Igor Bazarny earned 80 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 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