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