Well yes, Arie, you are right about that. I did find a clever/nasty (you
be the judge of that) solution for the problem. Simply write the
environment variable from within your application to a file, and then
"source" the file in your script. :-)
The script might look something like this:
[script]
#!/bin/sh
# create some environment variable 'EVR' and show it
EVR="your value"
echo $EVR
# run your C program, which changes EVR and exports it to
/tmp/evr.env
./your_c_program
# source the changed environment
source /tmp/evr.env
# now show the changed value
echo $EVR
# and exit the script.
exit 0
[/script]
In your C program, you would do something like this:
[snippet]
// Here, you change the environment variable
setenv("EVR", "my changed value", 1);
// Open a temp file to write the environment variable in
FILE *fh = fopen("/tmp/evr.env", "w+");
if (fh)
{
// This will write 'EVR="my changed value"' in the temp
file
fprintf(fh, "EVR=\"%s\"\n", getenv("EVR"));
fclose(fh);
}
[/snippet]
Regards,
Sander
-----Original Message-----
From: Arie de Muijnck [mailto:[email protected]]
Sent: Thursday, December 18, 2008 10:52 AM
To: Sander Huijsen; [email protected]
Subject: Re: A way to export from c an environment var
Unless one wants to set a persistant value, that can be used after
his/hers
process finishes...
Unfortunately functions like setenv(), putenv(), system("export ...")
change
only the current environment of the process itself, not the 'global'
environment of the user (let alone the system).
Regards,
Arie de Muijnck
----- Original Message -----
> 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-----
> 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
--------------------------------------------------------
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