Hi,
I think the following Microsoft statement should help here:
"getenv and _putenv use the copy of the environment pointed to by the global variable _environ to access the environment. getenv operates only on the data structures accessible to the run-time library and not on the environment "segment" created for the process by the operating system. "
I think you would need to use GetEnvironmentVariable instead
To answer it pretty short: It seems like getenv only looks at the global variables, and GetEnvironmentVariable works for application specific too
I modified the code to (change extension to .cpp)
#include <mex.h>
#include "Windows.h"
void mexFunction(int nargout, mxArray *pargout [ ], int nargin, const mxArray *pargin[])
{
const DWORD buff_size = 50;
LPTSTR buff = new TCHAR[buff_size];
DWORD var_size;
buff[0] = '\0';
printf("OS %s\n", getenv("OS"));
printf("AAA %s\n", getenv("AAA"));
var_size = GetEnvironmentVariable("AAA",buff,buff_size);
printf("AAA through GetEnvironmentVariable %s\n",buff);
}
And when you run it you see this:
>> test
OS Windows_NT
AAA (null)
AAA through GetEnvironmentVariable
>> setenv('AAA','BBB11')
>> test
OS Windows_NT
AAA (null)
AAA through GetEnvironmentVariable BBB11
>>
Best Answer