%PUTENV

%PUTENV


%POPEN Index Level %RDHEX
Syntax result = %PUTENV( string )
Category BASIC
Type C Function
Description makes the value of the environment variable name equal to the value designated by "string", by altering an existing variable or by creating a new one.

"string"   String of the form name=value.

"result"   Non-zero if the variable is added successfully to the environment, or 0 (zero) if an error occurred.

The environment contains a pointer to 'string', making it a mistake to use a FlashBASIC variable as 'string' (FlashBASIC variables are essentially volatile). Proper use requires using "%malloc()" to obtain non-FlashBASIC space, use "%strcpy()" to copy the FlashBASIC variable into it, and pass the malloced space to "%putenv", as in the example below.
Options
See Also CFUNCTION %GETENV %MALLOC SYSTEM environ env
Example Add the string 'port=current port.number' to the Unix environment of the process. After this small program has been executed, the TCL command 'env' now shows the port.number of the process. The TCL command "environ" does this kind of environment setting.

* Build the string
string='PORT_NUMBER=':system(22)
* get workspace (+1 for terminating NULL)
ptr=(char*)%malloc( 1+len(string) )
* Put the string into the allocated buff
%strcpy( (char*)ptr, string )
* Add it to the environment
%putenv( (char*)ptr )
Warnings
Compatibility D3/Unix
%POPEN Index Level %RDHEX