• 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

Using System.getenv()

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have set some environment variables in my unix OS and would like to retrieve them in windows OS. Can I use System.getenv("env var") in my java code running in Windows to do this?

Or, is there any other way of obtaining the same?

Thanks!!
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question doesn't seem to make sense: of course you can't read Unix environment variables on Windows.

If you mean "does getenv() work on Windows?", the answer is yes. Though it went through a period of being deprecated, it is now a proper interface again in the latest Java.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name, with a space in between. You can change your display name here. Thanks!
 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have had trouble with the environmental variables in UNIX when accessing them through Java (i.e. using exec, or getenv). I found that java doesnt correctly read my environmental variables ! For example, a quick "echo $PATH" yields a string with 5 path values in it (/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/:/usr/local/bin/MyPrograms) but in java, my "Path" as displayed using process.exec has only 3 entries (/bin:/sbin:/usr/bin:/usr/sbin).

Is there a way to force java to obtain the "Path" using the same method that my "shells" use ? I've never really thought about the shells and where they get their environmental variables from, but it seems like they always seem to work !
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi jay,
i don't think java is not able to read env variables properly. i just tried the same thing and got the following result

C:\ClarifyCRM12iSR1.04\Configurator\Common Files\CCAutomation;C:\ClarifyCRM12iSR
1.04\ClarifyClient;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Pr
ogram Files\Java\jdk1.5.0_07\bin

using System.getenv("PATH")

which is exactly same as what i get with echo command.

there may be some other scenario in which you are getting this problem.
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... do you think it is UNIX related ? Are there different PATH's for different processes in UNIX ?
 
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic