Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to get all of enviroment variables ?

Reply
Thread Tools

How to get all of enviroment variables ?

 
 
Nelson
Guest
Posts: n/a
 
      12-05-2006
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.


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      12-05-2006
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++.

 
Reply With Quote
 
 
 
 
Rud1ger Sch1erz
Guest
Posts: n/a
 
      12-05-2006
"Nelson" <(E-Mail Removed)> 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[i] != NULL; i++) {
cout << environ[i] << endl;
}

return 0;
}

</t5.cc>

Cheers,
Rudiger
 
Reply With Quote
 
Aman
Guest
Posts: n/a
 
      12-14-2006
> 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[i] != 0; ++i)
cout << envp[i] <<endl;
}

regards,
Aman.


--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
 
Reply With Quote
 
Gavin Deane
Guest
Posts: n/a
 
      12-14-2006

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: How to set or get enviroment variable Chris Angelico Python 0 03-30-2013 08:45 PM
How to set or get enviroment variable Nac Temha Python 0 03-30-2013 08:39 PM
Retrieving pre-set enviroment variables in DOS not working Girish Perl Misc 4 03-14-2007 11:15 AM
Python Enviroment Variables Ruchika Python 1 09-09-2004 07:28 AM



Advertisments