Linux - Obtain environment variables

Discussion in 'Java' started by pd, Jun 13, 2007.

  1. pd

    pd Guest

    guys,

    under linux, how can java access environment variables. currently i
    have something like,
    Properties envVars = new Properties();
    Runtime r = Runtime.getRuntim();
    Process p = null;
    p = r.exec("env");

    and this doesnt work. does anybody know how to get this to work.
    thanks a lot.
     
    pd, Jun 13, 2007
    #1
    1. Advertising

  2. pd

    stefanomnn Guest

    On 13 Giu, 07:26, pd <> wrote:
    > guys,
    >
    > under linux, how can java access environment variables. currently i
    > have something like,
    > Properties envVars = new Properties();
    > Runtime r = Runtime.getRuntim();
    > Process p = null;
    > p = r.exec("env");
    >
    > and this doesnt work. does anybody know how to get this to work.
    > thanks a lot.


    Hello!
    Did you try taking input stream from process?
     
    stefanomnn, Jun 13, 2007
    #2
    1. Advertising

  3. On Tue, 12 Jun 2007 22:26:47 -0700, pd wrote:
    > under linux, how can java access environment variables. currently i
    > have something like,
    > Properties envVars = new Properties();
    > Runtime r = Runtime.getRuntim();
    > Process p = null;
    > p = r.exec("env");
    >
    > and this doesnt work. does anybody know how to get this to work.


    "Something like" doesn't help anyone debug your real code.

    Try using Properties.load(InputStream), passing the p.getInputStream()
    as the argument.

    If that doesn't work, post a complete example.

    /gordon

    --
     
    Gordon Beaton, Jun 13, 2007
    #3
  4. pd

    stefanomnn Guest

    if you run on java 1.5,
    you needn't use Process class,
    toy can use System.getEnvs() method,
    which return you a map of all environnement settings
     
    stefanomnn, Jun 16, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leo
    Replies:
    2
    Views:
    3,001
    Gordon Beaton
    Mar 21, 2006
  2. Replies:
    3
    Views:
    342
    Ron Natalie
    Nov 3, 2004
  3. Replies:
    5
    Views:
    660
  4. Replies:
    9
    Views:
    960
  5. powah
    Replies:
    7
    Views:
    478
    kun niu
    Apr 23, 2009
Loading...

Share This Page