Questions tagged [getenv]

Anything related to C or C++ standard library functions `getenv` (C) or `std::getenv` (C++). These functions are used to get the value of an environment variable.

Anything related to C or C++ standard library functions getenv (defined in <stdlib.h> C standard header) or std::getenv (defined in <cstdlib> C++ standard header). These functions are used to get the value of an environment variable.

See CPPreference.com:

128 questions
44
votes
2 answers

Updated environment variable but os.getenv() keeps returning None

I can't seem to get my code to respond to custom environment variables so I wrote a piece of code to test it. os.getenv is not pulling the environment variables that I've set in BASH into my Python code. $ FRUSTRATION="PYTHON!!" $ echo…
aselya
  • 537
  • 2
  • 5
  • 9
17
votes
2 answers

How do I use putenv() to update existing environment variable?

Edit: as far as I can tell, my question is because of a defect in PHP. I've copied this question to the PHP bug tracker here: https://bugs.php.net/bug.php?id=74143 and plan to try and implement a fix. The putenv function sets the value of an…
Greg
  • 21,235
  • 17
  • 84
  • 107
14
votes
1 answer

os.getenv returns None instead correct value

I have a complex piece of software I am not able to post, nor do I have a concrete working example. I will try to explain the problem, maybe someone encountered this before. On the Linux shell I have defined an environment variable: > export…
Alex
  • 41,580
  • 88
  • 260
  • 469
13
votes
2 answers

"getenv... function ... may be unsafe" - really?

I'm using MSVC to compile some C code which uses standard-library functions, such as getenv(), sprintf and others, with /W3 set for warnings. I'm told by MSVC that: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
11
votes
4 answers

Standard C usage of getenv and safe practices

I am trying to write C code which makes use of some ENV variables in a UNIX environment. The question is: Could reading variables (for example getenv()) cause buffer overflow? Moreover, how can I find the limit of the env variable size for my…
user1944224
  • 143
  • 1
  • 1
  • 5
10
votes
1 answer

Why change in LD_LIBRARY_PATH at Runtime dosen't Reflect on the Executable once the Executable gets loaded

I'm trying to change the LD_LIBRARY_PATH from my C++ program. I'm able to get its value using getenv("LD_LIBRARY_PATH") and set its value using setenv() (and I know that this is working, because when I call getenv("LD_LIBRARY_PATH") again, I get the…
Thiyagarajan
  • 1,271
  • 1
  • 14
  • 19
8
votes
1 answer

Docker Alpine image + grpc: Warning: insecure environment read function 'getenv' used

When I used this image: node:6.11.0-alpine to run my service (use GRPC), then keep getting these warnings: D0622 06:52:01.170502843 1 env_linux.c:66] Warning: insecure environment read function 'getenv' used D0622…
lnshi
  • 2,310
  • 3
  • 19
  • 42
8
votes
3 answers

getenv Not Working for COLUMNS and LINES

I am trying to get the number of columns and lines in my program. I am using the following code to do so: ... char *cols = getenv("COLUMNS"); printf("cols: %s\n", cols); char *lines = getenv("LINES"); printf("lines: %s\n", lines); ... The…
carloabelli
  • 4,289
  • 3
  • 43
  • 70
6
votes
2 answers

TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' while using Python 3.7

I am trying to run the simple below snippet port = int(os.getenv('PORT')) print("Starting app on port %d" % port) I can understand the PORT is s string but I need to cast to a int. Why I am getting the error TypeError: int() argument must be a…
Andy
  • 405
  • 1
  • 5
  • 16
6
votes
4 answers

Cannot retrieve Apache environment variables in PHP

Background I have an Apache/2.2.15 (Win32) with PHP/5.3.2 set up, handling authentication. # core authentication and mod_auth_basic configuration # for mod_authn_dbd AuthType Basic AuthName "My Server" …
Max Kielland
  • 5,627
  • 9
  • 60
  • 95
5
votes
2 answers

Deleting char array returned by getenv()

Should I free the memory allocated for the char array, pointer to which is returned by the char * getenv( char * ) function? And which way - C free() or C+ delete []? If no - why? I mean: char * ptr = getenv( "LS_COLORS" ); cout << ptr <<…
G. Kashtanov
  • 401
  • 3
  • 11
5
votes
2 answers

C++ getenv doesnt update

I'm trying to make a program that a bash script runs. I want the bash script to be able to change the state of the c++ program, and the only thing I could find was to use environment variables. Thing is, its seems getenv only gets the value at the…
Joe Jankowiak
  • 1,059
  • 12
  • 37
4
votes
2 answers

zsh export with one argument does not seem to actually create environment variable

The command export FOO should, according to my understanding, create an environment variable FOO (with a blank value) even if this variable did not exist previously and no value was supplied. This position seems to be supported by the zsh manual. …
sasquires
  • 356
  • 3
  • 15
4
votes
2 answers

What can I do if getcwd() and getenv("PWD") don't match?

I have a build system tool that is using getcwd() to get the current working directory. That's great, except that sometimes people have spaces in their paths, which isn't supported by the build system. You'd think that you could just make a…
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
4
votes
3 answers

why getenv() can get name resolved without a std::?

getenv() has a C++ implementation which can be included in the header file . So it is a member of namespace std. However, the getenv() function can be get resolved correctly in my code even without a std::getenv(), which means my follow program can…
Banchon
  • 43
  • 1
  • 5
1
2 3
8 9