[UP]


Manual Reference Pages  - system_putenv (3)

NAME

system_putenv(3f) - [M_system:ENVIRONMENT] set environment variable from Fortran by calling putenv(3c) (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Example
Author
License

SYNOPSIS

subroutine system_putenv(string, err)

character(len=*),intent(in) :: string integer, optional, intent(out) :: err

DESCRIPTION

The system_putenv() function adds or changes the value of environment variables.

OPTIONS

string string of format "NAME=value". If name does not already exist in the environment, then string is added to the environment. If name does exist, then the value of name in the environment is changed to value. The string passed to putenv(3c) becomes part of the environment, so this routine creates a string each time it is called that increases the amount of memory the program uses.
err The system_putenv() function returns zero on success, or nonzero if an error occurs. A non-zero error usually indicates sufficient memory does not exist to store the variable.

EXAMPLE

Sample setting an environment variable from Fortran:

    program demo_system_putenv
    use M_system, only : system_putenv
    use iso_c_binding
    implicit none
    integer :: ierr
       !
       write(*,’(a)’)’no environment variables containing "GRU":’
       call execute_command_line(’env|grep GRU’)
       !
       call system_putenv(’GRU=this is the value’,ierr)
       write(*,’(a,i0)’)’now "GRU" should be defined: ’,ierr
       call execute_command_line(’env|grep GRU’)
       !
       call system_putenv(’GRU2=this is the second value’,ierr)
       write(*,’(a,i0)’)’now "GRU" and "GRU2" should be defined: ’,ierr
       call execute_command_line(’env|grep GRU’)
       !
       call system_putenv(’GRU2’,ierr)
       call system_putenv(’GRU’,ierr)
       write(*,’(a,i0)’)’should be gone, varies with different putenv(3c): ’,ierr
       call execute_command_line(’env|grep GRU’)
       write(*,’(a)’)’system_unsetenv(3f) is a better way to remove variables’
       !
    end program demo_system_putenv

Results:

   no environment variables containing "GRU":
   now "GRU" should be defined: 0
   GRU=this is the value
   now "GRU" and "GRU2" should be defined: 0
   GRU2=this is the second value
   GRU=this is the value
   should be gone, varies with different putenv(3c): 0
   system_unsetenv(3f) is a better way to remove variables

AUTHOR

John S. Urban

LICENSE

Public Domain


system_putenv (3) July 05, 2020
Generated by manServer 1.08 from 3f50e8fa-8e6a-44e4-91cc-1658631ad0b2 using man macros.