Solved

getProperty?

Posted on 2001-08-29
6
364 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
nestparen challenge 4 56
Requested array size exceeds VM limit 3 48
maven example error 3 36
Java Timer (static) 9 16
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

21 Experts available now in Live!

Get 1:1 Help Now