473,383 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to get all of enviroment variables ?

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.
Dec 5 '06 #1
4 5879
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++.

Dec 5 '06 #2
"Nelson" <ne****@mandela.orgwrites:
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
Dec 5 '06 #3
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
Dec 14 '06 #4

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

Dec 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: stud | last post by:
I dont know how to set enviroment variables for JRE on Win ME, or exactly what should they look like. I'm usin SDK.
1
by: Ruchika | last post by:
Hi, How can i get/set environment variables in Python? I am trying to run Perforce commands from Python script but am unsuccesful. Want to make sure that Perforce is in the path. How can I...
4
by: Benne Smith | last post by:
In our company, i have three servers; 1) a development server (mine only - here i make daily changes and test my stuff) 2) a test server (for the users to test milestone builds - changes weekly)...
0
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
3
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
1
by: Jason | last post by:
I'm trying to create some envirment variables but I'm having some trouble. Whats the correct way? This is what I've got in my C# application..... Environment.SetEnvironmentVariable("PYTHON",...
5
by: Henaro | last post by:
Hello~ I am having trouble setting environment variables in C++ on win32. The code that is not working is: char prxy; char pf_cmd1 = "set http_proxy="; ....
0
by: trr | last post by:
OK I am a newbie and just can't find the answer to the basic question: In ActionScript how do I get a System User Environment Variable. Something like: System.getenv("JAVA_HOME"):
1
by: jl880703 | last post by:
I am working with the java Process in Linux. I start new process but I can't set the variables enviroment for those processes I start. Example: I had two users in my pc main(super user)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.