[comp.unix.questions] Putenv

johnl@n3dmc.UUCP (John Limpert) (05/27/88)

I need to write a putenv() function for my SVR2 system.  I have
tried to add a string to the environment but it doesn't survive
an exec.  What is the correct method of making environment changes?

-- 
John A. Limpert
UUCP:	johnl@n3dmc.UUCP	uunet!n3dmc!johnl
PACKET:	n3dmc@n3dmc.ampr.org	n3dmc@wa3pxx

avr@mtgzz.UUCP (XMRP50000[jcm]-a.v.reed) (05/31/88)

In article <344@n3dmc.UUCP>, johnl@n3dmc.UUCP (John Limpert) writes:
> 
> I need to write a putenv() function for my SVR2 system.  I have
> tried to add a string to the environment but it doesn't survive
> an exec.  What is the correct method of making environment changes?

Use execve(), not execv(). After setting up the environment the way
you want it, call

	int exerror;
	exerror = execve (path, argv, envp);

where envp is an array of pointers to null-terminated strings
containing your environment. Read the manual page for details.

					Adam Reed (mtgzz!avr)

borzieri@KING.ICO.OLIVETTI.COM (Ivan Borzieri) (02/15/91)

Hi,

I URGENTLY need this information :

I wrote two c modules called by a fortran main.
in the first  c module I call the system function "putenv()" which should
set a variable in the environment.
In the second  c module I call the system function "getenv()" to read 
the value of the previous set variable.
The value returned by getenv() is NULL, id est, that variable
doesn't exist.

Now my question is : is this right ?
I know that in C-Shell scripts, when you set variables you loose them
as you exit the script.
Is it the same or this is a operating system bug ?

The system is SCO Unix System V 3.2

							Thanks,
							Ivan Borzieri