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
0
votes
2 answers

Environment variable $QUERY_STRING is not being included with *envp[]

I have set an environment variable with the following command: QUERY_STRING='This is my query string' This is my program: #include #include void main (int argc, char *argv[]) { printf("%s\n",…
Deanie
  • 2,316
  • 2
  • 19
  • 35
0
votes
1 answer

How to initialise an Ada Unbounded String from GetEnv & Literal

G'day, I'm finding compile errors on what ought to be a simple piece of code. the objective is to use an environment variable as part of a default value. We are using Ada95, so I wondered if it's a version thing. The 'model' we stated with looks…
will
  • 4,799
  • 8
  • 54
  • 90
0
votes
0 answers

Can't get Environmental variables into PHP Script

I have environmental variables set in /etc/bash.bashrc and profile. They work fine in shell scripts, but not php. I have tried: $VAR = getenv('VAR'); $VAR = $_ENV["VAR"]; If I run the php script from the command line, they print out ok. But if I…
Corepuncher
  • 375
  • 2
  • 4
  • 15
0
votes
0 answers

Detecting Gnome in C without GNOME_DESKTOP_SESSION_ID?

I'm trying to detect the user's desktop environment (Gnome, KDE, etc) in C. Currently, I'm doing something like this: if (getenv("GNOME_DESKTOP_SESSION_ID")) { // if getenv didn't return NULL, GNOME_DESKTOP_SESSION_ID must be defined } However,…
yossarian
  • 1,537
  • 14
  • 21
0
votes
0 answers

getenv returning different addresses

getenv("USER") returns two different addresses when called from two different functions. 0x7fff60e15e79 0x60e15e79 So in the second case the 7fff part is missing . This is leading to a crash when I try to print the string in the second case . Does…
Sumit Das
  • 1,007
  • 9
  • 17
0
votes
1 answer

Linux Environment Variable and C project getenv()

I need to use an environment variable for a C project so i did this in a terminal: export FILE_CONFIG="/home/pc/file.conf" file.conf is a file which i created. If I do env in the terminal, I can see "FILE_CONFIG" in the list with its value…
ank3r
  • 17
  • 5
0
votes
1 answer

getenv - how to set environment variable

I set environment variable this way: export MY_DIR="$HOME/projects" Then I want to read that variable in my program: char *name = getenv("MY_DIR"); but I get a null value, Edit 1: when I run the program using Qt Creator. When I compile: g++…
Irbis
  • 11,537
  • 6
  • 39
  • 68
0
votes
4 answers

C++ no 'object' file generated

This is some code to get an environment variable from inside Qt, however, it seems Qt's QProcessEnvironment::systemEnvironment() only reflect a new environment variable change after reboot. So I am thinking about using getenv. However I got "error…
Quaid Tseng
  • 41
  • 1
  • 1
  • 4
0
votes
1 answer

How to prevent SERVER['HTTP_REFERER'] switches to the calling page?

Please help. A link obtained by using $_SERVER['HTTP_REFERER'] in form.php like this:
0
votes
2 answers

Getting the getenv to work in Windows using Java

Hi I have been struggling to get the 'getenv' to work. it will keep on returning "Exception in thread "main" java.lang.UnsupportedOperationException". I have been reading about the ProcessBuilder but i am not quite sure on how and where to implement…
Luqman
  • 249
  • 4
  • 25
0
votes
2 answers

Get System Environmental Variables In C

I've written an application in C that is supposed to be reading environmental variables and handling those changes appropriately. When the application starts, I've set it up to go ahead and initialize the variable (to prevent any null pointers from…
Freesnöw
  • 30,619
  • 30
  • 89
  • 138
0
votes
3 answers

Can someone explain to me how the environ variable works in C++?

I'm trying to write my own version of getenv. I haven't started yet so I'm trying to understand environ first. If it's a global why can't I print it in my function? Is environ a String or an array of chars? Why is environ a double pointer? Thank…
Sal Rosa
  • 551
  • 2
  • 8
  • 12
0
votes
1 answer

program get stuck in getenv()

I am overloading "malloc" by pre-loading a library. In this custom "malloc", i am using environment variable to distinguish my program to use my custom "malloc" from the general "malloc". The problem is that, after several "mallocs" the program gets…
pratick
  • 303
  • 1
  • 3
  • 9
-1
votes
1 answer

Failing to set environment variable

Can someone please help me figure out why I'm not getting the results im supposed to? from the textbook #include #include #include int main(int argc, char *argv[]) { char *my_env[] = {"JUICE = peaches and…
-1
votes
1 answer

chdir(getenv("HOME") returns Bad address

char *home = getenv("HOME"); if (!strcmp(t->argv[0], "cd")) { if (!t->argv[1]) { chdir(home); } if (chdir(t->argv[1])) { perror(t->argv[1]); } } what this is supposed to…
1 2 3
8
9