aspose file tools*
The moose likes Java in General and the fly likes regarding user Environmental variable. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "regarding user Environmental variable." Watch "regarding user Environmental variable." New topic
Author

regarding user Environmental variable.

srinath jeyanthi
Greenhorn

Joined: Feb 14, 2001
Posts: 18
I want to get the user Environmental variable value.
i was tryed using java.lang.System.getProperties.but it is not working.please give the answer .
regards,
jeyanthi.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
It SHOULD work. So show us some code so we can see the problem.
However the API has this note:

Note that even if the security manager does not permit the getProperties operation, it may choose to permit the
getProperty(String) operation.


[This message has been edited by Cindy Glass (edited February 14, 2001).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
srinath jeyanthi
Greenhorn

Joined: Feb 14, 2001
Posts: 18
i was tryed the samething ie java.lang.System.getProperty(String)
but it gives the null values.please help me.

with regards,
jeyanthi.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
How did you SET the user property. If it is not set correctly, you will not be able to get it later.
Some code would help.
srinath jeyanthi
Greenhorn

Joined: Feb 14, 2001
Posts: 18
i was setted environmental varible through control panel system icon.under environmetal variable in that user variabl for
administrator.
surya gollamudi
Greenhorn

Joined: Oct 28, 2000
Posts: 7
Hi Jayanthi
I did a simple program .
It worked properly on WINNT except for variables having "_" in between .If you modify the code , it will work for variables having underscore inbetween.
You just replace the string "Systemroot" with whatever variable you want .
I didn't dealt with pr.getErrorStream .It is better to include that one also in your code.

=================================================================
import java.util.*;
import java.io.*;
class testing
{
public static void main(String args[])
{
testing a= new testing();
String check = new String("Systemroot");
int varlen = check.length();
String os = System.getProperty("os.name");
System.out.println(os);
String sendcommand="";
if( os.equals( "Windows NT" ) )
{
sendcommand = "cmd.exe /c set";
}
else
if(os.equals( "Windows 95" ) )
{
sendcommand = "command.com /c set";
}
Runtime r=Runtime.getRuntime();
try
{
Process pr = r.exec(sendcommand);
InputStream stdinp = pr.getInputStream();
InputStreamReader isrinp = new InputStreamReader(stdinp);
BufferedReader brinp = new BufferedReader(isrinp);
String lineinp = null;
while ( (lineinp = brinp.readLine()) != null)
{
if((lineinp.substring(0,varlen)).equalsIgnoreCase(check))
{
System.out.println(lineinp.substring(varlen+1));
}
}
}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
}
================================================================
If you are willing to supply the variable along with the "java"
command , see the reply that I gave for the posting http://www.javaranch.com/ubb/Forum34/HTML/000558.html

Even now if it won't solve your problem , just post your code.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You can set the operating system all you want, and Java is not going to know about it. The Properties that java knows how to get are listed in the API under System.getProperties. If you want to store more properties that that you have to go to create new properties in java, and load them yourself. Some applications have a .properties file to do this. At execution they read the .properties file and add those to the ones that java already knows about.
Josh Allen
Ranch Hand

Joined: Jan 15, 2005
Posts: 37
You can use System.getenv() which is no longer deprecated since JDK 1.5.

Javadoc
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: regarding user Environmental variable.