Hi,
I have tried some experiments along these lines.....
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *rc;
FILE *fp;
char buffer[256];
putenv("FRED=\"Hello World\"");
rc = getenv("FRED");
if(rc)
printf("rc: %s\n", rc);
else
printf("Not found\n");
fp = popen("export FRED=\"Goodbye\"", "r");
pclose(fp);
fp = popen("env|grep FRED", "r");
if(fp)
{
rc = fgets(buffer, sizeof(buffer), fp);
if(rc)
printf("returned: %s\n", buffer);
pclose(fp);
}
return 0;
}
....Checking after the program exits, it proves Rob Tivy is right (no
FRED defined). The variable is set only in the environment space of the
running program it cannot affect the parent process.
What was interesting is the 'popen' to set FRED="Goodbye" did not
persist, presumably it only existed in the shell created to execute the
command. The 'popen' to get the value of FRED returned the 'hello world'
set by 'putenv'.
Regards
Phil Q
Sander Huijsen wrote:
You might want to try setenv(). Just type 'man 3 setenv' in a Linux
shell to get the man-page for that function (which is in stdlib).
Sander
-----Original Message-----
From:
davinci-linux-open-source-bounces+shuijsen=optelecom-nkf....@linux.davin
cidsp.com
[mailto:davinci-linux-open-source-bounces+shuijsen=optelecom-nkf....@lin
ux.davincidsp.com] On Behalf Of Van Vliet
Sent: Wednesday, December 17, 2008 4:57 PM
To: [email protected]
Subject: A way to export from c an environment var
Hi,
Is there a way to create and export from c an environment
variable a bash
script can be aware of? I intend something like PATH, etc.
Thanks and Regards,
VanVliet
Dr. Caroline Van Vliet
Adfl Group
Advanced DSP Flexible Language Group
Via Greto di Cornigliano 6R
16152 - Genova, Italy
Tel. +39 010 8609370 - Fax +39 010 8609381
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
--------------------------------------------------------
CONFIDENTIALITY NOTICE - This e-mail transmission, and any documents, files or
previous e-mail messages attached to it may contain information that is
confidential or legally privileged. If you are not the intended recipient, or a
person responsible for delivering it to the intended recipient, you are hereby
notified that you must not read this transmission and that any disclosure,
copying, printing, distribution or use of any of the information contained in
or attached to this transmission is STRICTLY PROHIBITED. If you have received
this transmission in error, please immediately notify Sander Huijsen by
telephone or [email protected] and delete the original transmission
and its attachments without reading or saving in any manner.
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source