| Version: 3.3.1

Typedefs | Functions
Environment
Functions and Macros by Category

## Detailed Description

These functions allow access to get or change the values of environment variables in a portable way.

They are currently implemented under Win32 and POSIX-like systems (Unix).

Remember that these functions add/change/delete environment variables of the current process only. Child processes copy the environment variables of the parent, but do not share them (a wxSetEnv() in the parent process won't change the value returned by wxGetEnv() in the child process and vice versa).

For more advanced interprocess communication techniques see Interprocess Communication.

## Typedefs
using | wxEnvVariableHashMap = std::unordered_map< wxString, wxString >
| A map type containing environment variables names and values. More...

## Functions
char * | wxGetenv (const char *s)
| Wrapper of the standard `getenv()` or its wide char version. More...
wchar_t * | wxGetenv (const wchar_t *ws)
char * | wxGetenv (const wxString &s)
bool | wxGetEnv (const wxString &var, wxString *value)
| Returns the current value of the environment variable var in value. More...
bool | wxSetEnv (const wxString &var, const wxString &value)
| Sets the value of the environment variable var (adding it if necessary) to value. More...
bool | wxUnsetEnv (const wxString &var)
| Removes the variable var from the environment. More...
bool | wxGetEnvMap (wxEnvVariableHashMap *map)
| Fill a map with the complete content of current environment. More...

## Typedef Documentation

## ◆ wxEnvVariableHashMap

using wxEnvVariableHashMap = std::unordered_map<wxString, wxString>

A map type containing environment variables names and values.

This type is used with wxGetEnvMap() function and wxExecuteEnv structure optionally passed to wxExecute().

Since
  2.9.2

Include file:

    #include <wx/utils.h>

## Function Documentation

## ◆ wxGetenv() [1/3]

char* wxGetenv | ( | const char * | s | ) |

Wrapper of the standard `getenv()` or its wide char version.

Note that under Win32 the overload using `char*` does not work for variables using non-ASCII characters, use either the overload taking `wchar_t*` or, preferably, wxGetEnv() instead.

Under other platforms, `char*` overload always uses UTF-8 encoding.

Include file:

    #include <wx/utils.h>

## ◆ wxGetenv() [2/3]

wchar_t* wxGetenv | ( | const wchar_t * | ws | ) |

## ◆ wxGetenv() [3/3]

char* wxGetenv | ( | const wxString & | s | ) |

## ◆ wxGetEnv()

bool wxGetEnv | ( | const wxString & | var,
|  | wxString * | value
| ) |  |

Returns the current value of the environment variable var in value.

value may be nullptr if you just want to know if the variable exists and are not interested in its value.

Returns true if the variable exists, false otherwise.

Include file:

    #include <wx/utils.h>

## ◆ wxGetEnvMap()

bool wxGetEnvMap | ( | wxEnvVariableHashMap * | map | ) |

Fill a map with the complete content of current environment.

The map will contain the environment variable names as keys and their values as values.

Parameters

  map | The environment map to fill, must be non-null.

Returns
  true if environment was successfully retrieved or false otherwise.

Include file:

    #include <wx/utils.h>

Since
  2.9.2

## ◆ wxSetEnv()

bool wxSetEnv | ( | const wxString & | var,
|  | const wxString & | value
| ) |  |

Sets the value of the environment variable var (adding it if necessary) to value.

Notice that under Windows platforms the program may have two different environment blocks: the first one is that of a Windows process and is always present, but the CRT may maintain its own independent copy of the environment. wxSetEnv() will always update the first copy, which means that wxGetEnv(), which uses it directly, will always return the expected value after this call. But wxSetEnv() only updates the second copy for some compilers/CRT implementations (currently only MSVC and MinGW which uses the same MSVC CRT) and so using wxGetenv() (notice the difference in case) may not return the updated value.

Parameters

  var | The environment variable to be set, must not contain `'='` character.
  value | New value of the variable.

Returns
  true on success or false if changing the value failed.

See also
  wxUnsetEnv()

Include file:

    #include <wx/utils.h>

## ◆ wxUnsetEnv()

bool wxUnsetEnv | ( | const wxString & | var | ) |

Removes the variable var from the environment.

wxGetEnv() will return nullptr after the call to this function.

Returns true on success.

Include file:

    #include <wx/utils.h>