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. Advertisements

  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. Advertisements

  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. Advertisements

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. =?Utf-8?B?TmV3Ymll?=

    HttpSessionState.Abandon() from ASP Enviroment?

    =?Utf-8?B?TmV3Ymll?=, May 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    623
    Nicole Calinoiu
    May 31, 2004
  2. =?Utf-8?B?QW1pdA==?=

    Hosted Enviroment Problem

    =?Utf-8?B?QW1pdA==?=, Aug 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,172
    =?Utf-8?B?QW1pdA==?=
    Aug 14, 2004
  3. David
    Replies:
    4
    Views:
    537
    David
    Aug 8, 2005
  4. Ruchika

    Python Enviroment Variables

    Ruchika, Sep 9, 2004, in forum: Python
    Replies:
    1
    Views:
    734
    Miki Tebeka
    Sep 9, 2004
  5. Replies:
    9
    Views:
    1,319
  6. SAN CAZIANO
    Replies:
    1
    Views:
    382
  7. Girish
    Replies:
    4
    Views:
    166
    Girish
    Mar 14, 2007
  8. Nac Temha
    Replies:
    0
    Views:
    169
    Nac Temha
    Mar 30, 2013
Loading...