473,387 Members | 1,528 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,387 software developers and data experts.

Enviroment variable on Linux _and_ Windows

Hi All!

If anybody know, how I cann set an enviroment variable (with ANSI C) on
Windows similar like on Linux. I tried setenv, but the function doesn't work
correct on Windows - it sets env. variables only for calling process or
session (in my case, the program will called in cmd.exe), but I need its
global. There is no putenv on Windows, only _putenv and there is no _putenv
on Linux (or I'm wrong?). I cann use of course something like this:
#if WIN32
#define putenv _putenv
#endif

and then compile with -DWIN32, but I would use a funktion, that implements
(and works correct - in my case, sets env. variables global for whole OS) as
well on Linux as on Windows.

Any help will be approtiate.
Thanks.
Andrey Litovka.
Nov 13 '05 #1
2 10309
Andrej Litowka <a.*******@gmx.de> wrote:
If anybody know, how I cann set an enviroment variable (with ANSI C) on
Windows similar like on Linux. I tried setenv, but the function doesn't work
correct on Windows - it sets env. variables only for calling process or
session (in my case, the program will called in cmd.exe), but I need its
global. There is no putenv on Windows, only _putenv and there is no _putenv
on Linux (or I'm wrong?). I cann use of course something like this:
#if WIN32
#define putenv _putenv
#endif

and then compile with -DWIN32, but I would use a funktion, that implements
(and works correct - in my case, sets env. variables global for whole OS) as
well on Linux as on Windows.


Sorry, neither setenv() nor putenv() nor environment variables or
the possible differences between Linux and Windows are on-topic
here because they're outside of the realm of standard C.

<OT>
You can't set an environment variable in a program and then have it
being set also in the calling process - the environment is a per-
process resource, not something global for all processes. So a
change of an environment variable always applies only to the
current process and its descendants (when created afterwards),
but never to its ancestors. There's no difference between setenv()
or putenv() in this respect. What you want to do can be achieved
by e.g. having your program outputting a string with what the
environment variable is to be set to and the calling program then
setting the variable to this string, but it always requires the
active participation of the calling process.
</OT>
Regards, Jens
--
_ _____ _____
| ||_ _||_ _| Je***********@physik.fu-berlin.de
_ | | | | | |
| |_| | | | | | http://www.physik.fu-berlin.de/~toerring
\___/ens|_|homs|_|oerring
Nov 13 '05 #2
On Wed, 17 Sep 2003 09:14:19 +0200, "Andrej Litowka"
<a.*******@gmx.de> wrote in comp.lang.c:
Hi All!

If anybody know, how I cann set an enviroment variable (with ANSI C) on


You can't set environment variables in ANSI/ISO C at all, on any
operating system. setenv() is not a standard C function. There is no
standard C function for setting environment variables at all.

What you need is a compiler/OS extension, which is off-topic here.
Ask in a Windows programming group such as
comp.os.ms-windows.win32.programmer.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #3

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

Similar topics

2
by: Nikhil Barthwal | last post by:
Hi, I have a Java program that needs to access the value of variable PATH (Set in Unix enviroment by setenv or DOS enviroment by PATH statement). How do I access it in Java? Thanks in...
13
by: Peter Maas | last post by:
Recently I replaced Win2k with Linux on my desktop computer. Using mostly multi-platform software I thought this would be easy. It was not as easy as expected getting wxPython to work. There seemed...
6
by: Todd | last post by:
Hello, How do I register and non .net dll(with the OS) in a .net enviroment? I have a third party dll I need to register(REGSVR32.EXE). What is the best approach to this in a .Net enviroment. ...
3
by: Informer | last post by:
Does any one know any website that I can find examples of C code in Unix Enviroment? Thanks
42
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
53
by: noahmd | last post by:
Okay, once-upon-a-time I tried to start programming by learning C. At the time I was younger and didn't really understand all that C had to offer. I eventually moved over to Microsoft's Visual...
11
by: Googy | last post by:
Hi friends!! As we know that the input parameters in a function is fixed when the function is defined but how does printf processes variable number of input arguments ? For example: 1....
1
by: Chuck Chopp | last post by:
I have some code that is being built on the following: Windows Server 2003, both 32-bit & 64-bit editions Windows Vista, both 32-bit & 64-bit editions Windows Server 2008, both 32-bit & 64-bit...
9
by: George | last post by:
I am trying to implement postponed initialization (object is not initialize till requested). public class clsStore { volatile List<clsPictureGroup_lstPictureGroups = null; public...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.