Read an enviroment variable from a java program

Posted on 2001-06-10
Last Modified: 2008-02-01
I want to get an enviroment variable from a java program.
Can you help me?
Question by:rzvika
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
  • 4
  • 3

Expert Comment

ID: 6172950
public static Properties java.lang.System.getProperties()

Determines the current system properties.
If there is a security manager, its checkPropertiesAccess method is called with no arguments. This may result in a security exception.

The current set of system properties is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized.

This set of system properties always includes values for the following keys: Key Description of Associated Value
java.version Java version number
java.vendor Java vendor-specific string
java.vendor.url Java vendor URL
java.home Java installation directory
java.class.version Java class format version number
java.class.path Java class path Operating system name
os.arch Operating system architecture
os.version Operating system version
file.separator File separator ("/" on UNIX)
path.separator Path separator (":" on UNIX)
line.separator Line separator ("\n" on UNIX) User's account name
user.home User's home directory
user.dir User's current working directory

public static String java.lang.System.getProperty(String key)

Gets the system property indicated by the specified key.
First, if there is a security manager, its checkPropertyAccess method is called with the key as its argument. This may result in a system exception.

If there is no current set of system properties, a set of system properties is first created and initialized in the same manner as for the getProperties method.

key - the name of the system property.
the string value of the system property, or null if there is no property with that key.


Author Comment

ID: 6172968
It doesn't know even the PATH variable.
I think it contains a small amount of properties related to java (but it definitely doesn't contain others)

Expert Comment

ID: 6172975
i really don't sure about most of evnironment variables, because of system dependency... maybe native methods can help

Technology Partners: 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!


Accepted Solution

Andrey_Kulik earned 100 total points
ID: 6173061

i hope this helps

java.util.Properties prop = new java.util.Properties(); in = new"cmd /C set").getInputStream()));
while (true)
  String str = in.readLine();
  if (str != null)
     int index = str.indexOf("=");
     if (index != -1)
       prop.put(str.substring(0, index), str.substring(index+1));
  } else


Best regards

Author Comment

ID: 6173137
Will be it good for unix too ?

Expert Comment

ID: 6173144
it won't be good for unix because of "cmd /C set", which is windows nt/2000 command. for unix run just "set".


Author Comment

ID: 6177282
1. The command for Sun OS is: "command set"
2. When I try in Win98 "command /C set" it thrwos me this: CreateProcess: command /C set  error=0    
at java.lang.Win32Process.create(Native Method)    
at java.lang.Win32Process.<init>(Unknown Source)    
at java.lang.Runtime.execInternal(Native Method)    
at java.lang.Runtime.exec(Unknown Source)    
at java.lang.Runtime.exec(Unknown Source)    
at java.lang.Runtime.exec(Unknown Source)    
at avaya.util.EnvironmentVariables.init(    
at avaya.util.EnvironmentVariablesApplet.init(    
at Source)    
at Source)

Author Comment

ID: 6186217
I've succeeded, the command is:
" /C set"

...but I do have a proplem:
The console window is opened and I don't want it.
Is there a way to open it minimized ?

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use lov values 2 72
eclipse console opening separately 2 38
Problem to Alipay 10 71
American Express @Work site and Java 4 67
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

733 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