Ok, not seeing any reply, I try to pose the question in a more general mode:
From within a C++ program I need to set a shell global variable in a permanent mode, such that the variable with its content will be available after the program terminates.
Any idea how to achieve that?
===================================
From within a C++ program I need to set a shell (bash) variable in a permanent mode, such that when the program will be launched again later, it will find that variable with the value previously set.
I'm confused about the scope of a variable set with putenv():
Doing simply this...
1 2 3
|
char bashVar[80]="MYVAR=aString";
putenv(bashVar);
system("echo $MYVAR"); // prints the *correct* content of MYVAR
|
...I notice that once the program terminates, $MYVAR is empty: the command >echo $MYVAR prints nothing.
So, what is the scope of MYVAR?
Unfortunately, this does not work because of the blank space in the string:
1 2 3
|
char bashVar[80]="export MYVAR=aString";
putenv(bashVar);
system("echo $MYVAR"); // prints nothing
|
I'd appreciate some direction. Thanks.