Solved

getProperty?

Posted on 2001-08-29
6
365 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 77
groupSumClump challenge 9 103
numbers ascending pyramid 100 141
Java Server Faces parameter pass? 6 39
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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 …

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now