Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding user Environmental variable.

 
srinath jeyanthi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
srinath jeyanthi
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was setted environmental varible through control panel system icon.under environmetal variable in that user variabl for
administrator.
 
surya gollamudi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use System.getenv() which is no longer deprecated since JDK 1.5.

java.lang.String;&41;" target="_blank" rel="nofollow">Javadoc
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic