DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    SNP Guest

    Environmental Variables in Java Program


    Can we pull out the environmental variables and their associated value which
    are set in the Operating System to our java program?

    eg: in one MS DOS window I set,

    set xyz=Just For Testing;
    set path=c:\jdk1.2.2\bin;

    can I read the value of the above 2 environmental variables in a java program
    which I execute in the same window?

    I tried, System.getProperties(), It returns only some std env variables...

    SNP


  2. #2
    John Timney (MVP) Guest

    Re: Environmental Variables in Java Program

    I dont think you can read all the environment variables for all systems -
    just the common ones which is why you probably cant see the ones you need.

    Try starting the JVM with the "-D" switch to pass properties to the
    application and read them with the System.getProperty() method like you
    would pass command line values to an exe.

    eg.
    java -Dxyz="%Just For Testing%" myJavaProgram

    --
    Regards

    John Timney
    Microsoft MVP
    (http://support.microsoft.com/support/mvp/program.asp)
    Co-Author Professional JSP
    ISBN: 1-861003-62-5



    SNP <shankar1972@yahoo.com> wrote in message
    news:39a6b2f3$1@news.devx.com...
    >
    > Can we pull out the environmental variables and their associated value

    which
    > are set in the Operating System to our java program?
    >
    > eg: in one MS DOS window I set,
    >
    > set xyz=Just For Testing;
    > set path=c:\jdk1.2.2\bin;
    >
    > can I read the value of the above 2 environmental variables in a java

    program
    > which I execute in the same window?
    >
    > I tried, System.getProperties(), It returns only some std env variables...
    >
    > SNP
    >




  3. #3
    Patel Guest

    Re: Environmental Variables in Java Program


    "SNP" <shankar1972@yahoo.com> wrote:
    >
    >Can we pull out the environmental variables and their associated value which
    >are set in the Operating System to our java program?
    >
    >eg: in one MS DOS window I set,
    >
    >set xyz=Just For Testing;
    >set path=c:\jdk1.2.2\bin;
    >
    >can I read the value of the above 2 environmental variables in a java program
    >which I execute in the same window?
    >
    >I tried, System.getProperties(), It returns only some std env variables...
    >
    >SNP
    >


    Well the other way is you can read your autoexec.bat file through your program.
    or you could write native mathods.

    Hope this will helpful. Regards


  4. #4
    Patel Guest

    Re: Environmental Variables in Java Program


    "Patel" <wonderful_me_us@yahoo.com> wrote:
    >
    >"SNP" <shankar1972@yahoo.com> wrote:
    >>
    >>Can we pull out the environmental variables and their associated value

    which
    >>are set in the Operating System to our java program?
    >>
    >>eg: in one MS DOS window I set,
    >>
    >>set xyz=Just For Testing;
    >>set path=c:\jdk1.2.2\bin;
    >>
    >>can I read the value of the above 2 environmental variables in a java program
    >>which I execute in the same window?
    >>
    >>I tried, System.getProperties(), It returns only some std env variables...
    >>
    >>SNP
    >>

    >
    >Well the other way is you can read your autoexec.bat file through your program.
    >or you could write native mathods.
    >
    >Hope this will helpful. Regards
    >

    Sorry, If you are using multiple window then you have diff. DOS sessions.
    and if you set something in one window you will not get that values in another
    window. I hope you are not doing this.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links