0

I am trying to set env variables using setenv function. But unfortunately it doesn't work as expected.

int setNewEnvVariable(const std::string *varName, const std::string *value)
{
    setenv(varName->c_str(), value->c_str(), true);
    return this->VAR_ADDED;
} 

It seems to work only when it wants. Sometimes I can change (replace) variable, but than it doesn't do any changes. I cannot add new variable at all. I have tried to use putenv. But it didn't help

I have found when it doesn't change existed variable. When I try to add new variable nonexistent yet. after this it doesn't add new variable , but in addition it doesn't change existed variable ,but before trying to add new variable everything worked.

I mean that before trying to add new var it accepts changing of existent for example PATH, but after passing nonexistent variable like PATH2323 , it stops to accept changing existed vars.

EDIT

I have checked return value it is 0 and errno also 0........ What is wrong with it ?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
ahguobrf
  • 85
  • 1
  • 6

0 Answers0