• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

regarding user Environmental variable.

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was setted environmental varible through control panel system icon.under environmetal variable in that user variabl for
administrator.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use System.getenv() which is no longer deprecated since JDK 1.5.

Javadoc
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic