How to get all of enviroment variables ?

Discussion in 'C++' started by Nelson, Dec 5, 2006.

  1. Nelson

    Nelson Guest

    Hi people,

    I know that getenv() returns the value of single environment variable,
    but I need some function that returns all of env. variables
    (just like when we type SET in commandline or similar).

    Any help ?

    Thanks
    Nelson.
     
    Nelson, Dec 5, 2006
    #1
    1. Advertising

  2. Nelson

    Rolf Magnus Guest

    Nelson wrote:

    > Hi people,
    >
    > I know that getenv() returns the value of single environment variable,
    > but I need some function that returns all of env. variables
    > (just like when we type SET in commandline or similar).


    Not possible in standard C++.
     
    Rolf Magnus, Dec 5, 2006
    #2
    1. Advertising

  3. "Nelson" <> writes:

    > I know that getenv() returns the value of single environment variable,
    > but I need some function that returns all of env. variables
    > (just like when we type SET in commandline or similar).


    Well, that's more a operating system question. Anyway, on a unix box
    this would normally work:

    <t5.cc>

    #include <iostream>

    extern char** environ;

    int main(int argc, char** argv)
    {
    int i;
    for(i = 0; environ != NULL; i++) {
    cout << environ << endl;
    }

    return 0;
    }

    </t5.cc>

    Cheers,
    Rudiger
     
    Rud1ger Sch1erz, Dec 5, 2006
    #3
  4. Nelson

    Aman Guest

    > Well, that's more a operating system question. Anyway, on a unix box
    > this would normally work:
    >


    Another version, maybe non standard , works on both with unix/gcc4.0.2
    and
    windows/VC7
    FYI.

    #include <iostream>
    using namespace std;

    int main(int argc, char* argv[], char* envp[])
    {
    for (int i = 0; envp != 0; ++i)
    cout << envp <<endl;
    }

    regards,
    Aman.


    --
    Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
     
    Aman, Dec 14, 2006
    #4
  5. Nelson

    Gavin Deane Guest

    Aman wrote:

    > Another version, maybe non standard ,


    It is non-standard

    > works on both with unix/gcc4.0.2
    > and
    > windows/VC7


    <snip>

    > int main(int argc, char* argv[], char* envp[])


    The only signatures required to be supported for main are

    int main()
    int main(int argc, char* argv[])

    The implementation is allowed to provide
    int main( /* anything else it likes */ )
    as an extension.

    <OT>
    Of course, the signature you suggested could be a widely enough
    supported extension that it is useful to the OP, given that no standard
    solution exists.
    </OT>

    Gavin Deane
     
    Gavin Deane, Dec 14, 2006
    #5
    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. Ruchika

    Python Enviroment Variables

    Ruchika, Sep 9, 2004, in forum: Python
    Replies:
    1
    Views:
    644
    Miki Tebeka
    Sep 9, 2004
  2. Girish
    Replies:
    4
    Views:
    105
    Girish
    Mar 14, 2007
  3. Nac Temha
    Replies:
    0
    Views:
    87
    Nac Temha
    Mar 30, 2013
  4. Chris Angelico

    Re: How to set or get enviroment variable

    Chris Angelico, Mar 30, 2013, in forum: Python
    Replies:
    0
    Views:
    102
    Chris Angelico
    Mar 30, 2013
  5. Chris Angelico

    Re: How to set or get enviroment variable

    Chris Angelico, Mar 30, 2013, in forum: Python
    Replies:
    0
    Views:
    94
    Chris Angelico
    Mar 30, 2013
Loading...

Share This Page