File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using System.getenv()

 
ram shyam
Ranch Hand
Posts: 77
  • 0
  • Mark post as helpful
  • send pies
  • 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!!
 
Peter Chase
Ranch Hand
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
jay vas
Ranch Hand
Posts: 407
  • 0
  • Mark post as helpful
  • send pies
  • 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 !
 
gaurav abbi
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... do you think it is UNIX related ? Are there different PATH's for different processes in UNIX ?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic