Hi Geoff, a process can only modify the environment of itself and its children. If you run your program from a shell, the shell is its parent and the program cannot modify the shell's environment, nor can it modify the environment of any other programs invoked from that shell or other random shells. But it can set the environment of programs it exec()'s.
if you need to read the data from another session, or you need to monitor a changing state, you'd be better off communicating via a file of some kind. Conrad. On Wed, Mar 06, 2002 at 09:48:17AM +0800, Gatward, Geoff wrote: > Hi, > > I'm hoping that somebody might be able to help me with a hopefully simple > programming query. > > I am in the process of writing a bit of code in C that looks at the parallel > port and sets an environment variable depending on the state of the pins. I > need this to be accessible to a bash script which performs some other > functions. > So far I have the interfacing to the port working fine, but I cannot set the > environment variable. > > I have used getenv() to READ an environment variable, and this works fine. > I am trying to use putenv() to set a variable called PINSTAT, but when I > check it is still set to a null value. One thought was that the variable > only remains set whilst the program is running, so I set a do/while loop to > continually set it. Even with my program in a loop, from another session, > an > "echo $PINSTAT" still shows a null. > > I have read a few bits and pieces about glibc's putenv() function not > working correctly - is this my problem and is there a way around it? > > Setup is Redhat Linux 6.2, gcc and glibc-2.1.3-23 if this helps. > > Thanks in advance, > > Geoff > > > > > -- > SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ > More Info: http://lists.slug.org.au/listinfo/slug -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ More Info: http://lists.slug.org.au/listinfo/slug