<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic I assume the interest is in in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053038#M115644</link>
    <description>&lt;P&gt;I assume the interest is in altering an environment variable in the underlying shell under which the Fortran program is running. If so then SYSTEM and EXECUTE_COMMAND_LINE would not be applicable as those affect a separate instance of a shell spawned for the former, and the local context of spawned processes for the latter.&lt;/P&gt;

&lt;P&gt;If you can share your source code with us for the SETENVQQ method then we would be able to help get that working for you.&lt;/P&gt;

&lt;P&gt;Here is a quick (and not so pretty) example borrowing example code from the Fortran User's Guide from SETENVQQ, GET_ENVIRONMENT_VARIABLE, and .EXECUTE_COMMAND_LINE.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program env_example
implicit none

&amp;nbsp; call my_setenvqq
&amp;nbsp; call my_execute_command_line

end program env_example

subroutine my_setenvqq
USE IFPORT
implicit none
character name*20
logical(4) success

&amp;nbsp; success = SETENVQQ("PATH=c:\mydir\tmp")
&amp;nbsp; name='PATH'
&amp;nbsp; call my_getenv(name)

end subroutine&amp;nbsp; my_setenvqq

subroutine my_execute_command_line
implicit none
integer :: CSTAT, ESTAT
character(100) :: CMSG
character name*20

&amp;nbsp; call EXECUTE_COMMAND_LINE ("export LIB=/mydir2/tmp;echo ' LIB is: '$LIB", &amp;amp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; EXITSTAT=ESTAT, CMDSTAT=CSTAT, CMDMSG=CMSG)

&amp;nbsp; if (CSTAT &amp;gt; 0) then
&amp;nbsp;&amp;nbsp;&amp;nbsp; print *, "Command execution failed with error ", TRIM(CMSG)
&amp;nbsp; else if (CSTAT &amp;lt; 0) then
&amp;nbsp;&amp;nbsp;&amp;nbsp; print *, "Command execution not supported"
&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; print *, "Command completed with status ", ESTAT
&amp;nbsp; end if

&amp;nbsp; name='LIB'
&amp;nbsp; call my_getenv(name)

end subroutine my_execute_command_line

subroutine my_getenv(name)
implicit none
character name*20, val*40
integer len, status

&amp;nbsp; call get_environment_variable (name, val, len, status, .true.)

&amp;nbsp; if (status .ge. 2) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'get_environment_variable failed: status = ', status
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop
&amp;nbsp; end if

&amp;nbsp; if (status .eq. 1) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'env var does not exist'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop
&amp;nbsp; end if

&amp;nbsp; if (status .eq. -1) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'env var length = ', len, ' truncated to 40'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = 40
&amp;nbsp; end if

&amp;nbsp; if (len .eq. 0) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'env var exists&amp;nbsp; but has no value'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop
&amp;nbsp; end if

&amp;nbsp; write (*,*) 'env var value = ', val (1:len)

end subroutine my_getenv&lt;/PRE&gt;

&lt;PRE class="brush:bash;"&gt;$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.0.109 Build 20150815
Copyright (C) 1985-2015 Intel Corporation.&amp;nbsp; All rights reserved.

$ ifort u594761.f90&amp;nbsp; ;&amp;nbsp; ./a.out
&amp;nbsp;env var value = c:\mydir\tmp
&amp;nbsp;LIB is: /mydir2/tmp
&amp;nbsp;Command completed with status&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0
&amp;nbsp;env var does not exist&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2015 09:56:33 GMT</pubDate>
    <dc:creator>Kevin_D_Intel</dc:creator>
    <dc:date>2015-09-30T09:56:33Z</dc:date>
    <item>
      <title>Setting environment variable</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053037#M115643</link>
      <description>&lt;P&gt;Hi All I am facing issue in setting environment variable in the linux platform using a fortran code.I have tried with SETENVQQ and export command inside the SYSTEM function and EXECUTE_COMMAND_LINE function.Please help me to solve this issue. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2015 17:04:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053037#M115643</guid>
      <dc:creator>Madhubalan_R_</dc:creator>
      <dc:date>2015-09-29T17:04:32Z</dc:date>
    </item>
    <item>
      <title>I assume the interest is in</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053038#M115644</link>
      <description>&lt;P&gt;I assume the interest is in altering an environment variable in the underlying shell under which the Fortran program is running. If so then SYSTEM and EXECUTE_COMMAND_LINE would not be applicable as those affect a separate instance of a shell spawned for the former, and the local context of spawned processes for the latter.&lt;/P&gt;

&lt;P&gt;If you can share your source code with us for the SETENVQQ method then we would be able to help get that working for you.&lt;/P&gt;

&lt;P&gt;Here is a quick (and not so pretty) example borrowing example code from the Fortran User's Guide from SETENVQQ, GET_ENVIRONMENT_VARIABLE, and .EXECUTE_COMMAND_LINE.&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program env_example
implicit none

&amp;nbsp; call my_setenvqq
&amp;nbsp; call my_execute_command_line

end program env_example

subroutine my_setenvqq
USE IFPORT
implicit none
character name*20
logical(4) success

&amp;nbsp; success = SETENVQQ("PATH=c:\mydir\tmp")
&amp;nbsp; name='PATH'
&amp;nbsp; call my_getenv(name)

end subroutine&amp;nbsp; my_setenvqq

subroutine my_execute_command_line
implicit none
integer :: CSTAT, ESTAT
character(100) :: CMSG
character name*20

&amp;nbsp; call EXECUTE_COMMAND_LINE ("export LIB=/mydir2/tmp;echo ' LIB is: '$LIB", &amp;amp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp; EXITSTAT=ESTAT, CMDSTAT=CSTAT, CMDMSG=CMSG)

&amp;nbsp; if (CSTAT &amp;gt; 0) then
&amp;nbsp;&amp;nbsp;&amp;nbsp; print *, "Command execution failed with error ", TRIM(CMSG)
&amp;nbsp; else if (CSTAT &amp;lt; 0) then
&amp;nbsp;&amp;nbsp;&amp;nbsp; print *, "Command execution not supported"
&amp;nbsp; else
&amp;nbsp;&amp;nbsp;&amp;nbsp; print *, "Command completed with status ", ESTAT
&amp;nbsp; end if

&amp;nbsp; name='LIB'
&amp;nbsp; call my_getenv(name)

end subroutine my_execute_command_line

subroutine my_getenv(name)
implicit none
character name*20, val*40
integer len, status

&amp;nbsp; call get_environment_variable (name, val, len, status, .true.)

&amp;nbsp; if (status .ge. 2) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'get_environment_variable failed: status = ', status
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop
&amp;nbsp; end if

&amp;nbsp; if (status .eq. 1) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'env var does not exist'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop
&amp;nbsp; end if

&amp;nbsp; if (status .eq. -1) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'env var length = ', len, ' truncated to 40'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = 40
&amp;nbsp; end if

&amp;nbsp; if (len .eq. 0) then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; write (*,*) 'env var exists&amp;nbsp; but has no value'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stop
&amp;nbsp; end if

&amp;nbsp; write (*,*) 'env var value = ', val (1:len)

end subroutine my_getenv&lt;/PRE&gt;

&lt;PRE class="brush:bash;"&gt;$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.0.109 Build 20150815
Copyright (C) 1985-2015 Intel Corporation.&amp;nbsp; All rights reserved.

$ ifort u594761.f90&amp;nbsp; ;&amp;nbsp; ./a.out
&amp;nbsp;env var value = c:\mydir\tmp
&amp;nbsp;LIB is: /mydir2/tmp
&amp;nbsp;Command completed with status&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0
&amp;nbsp;env var does not exist&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2015 09:56:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053038#M115644</guid>
      <dc:creator>Kevin_D_Intel</dc:creator>
      <dc:date>2015-09-30T09:56:33Z</dc:date>
    </item>
    <item>
      <title>If you want to stick to the</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053039#M115645</link>
      <description>&lt;P&gt;If you want to stick to the standard and avoid using extensions that are dependent on the compiler, you could employ C bindings to call a C function that sets the environment variable.&lt;/P&gt;

&lt;P&gt;Take a look at the sample codes:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdlib.h&amp;gt;

void set_ev()
{
   setenv("MY_ENV_VAR", "Hey, what's up!",1);
}
&lt;/PRE&gt;

&lt;P&gt;------------------------------------------------------------------------------------------------------&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;program tes_set_ev
use, intrinsic :: iso_c_binding
implicit none
character(len= 50) :: sys_ev
INTERFACE
   subroutine set_ev() bind(c)
   end subroutine set_ev
END INTERFACE
!
call get_environment_variable('MY_ENV_VAR', sys_ev)
print*, 'Before calling c void: -&amp;gt;|'//trim(sys_ev)//'|&amp;lt;-'
call set_ev()
call get_environment_variable('MY_ENV_VAR', sys_ev)
print*, 'After calling c void: -&amp;gt;|'//trim(sys_ev)//'|&amp;lt;-'
end program tes_set_ev&lt;/PRE&gt;

&lt;P&gt;-------------------------------------------------------------------------------------------------------------------&lt;/P&gt;

&lt;P&gt;This is the compilation lines and the output:&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;$&amp;gt;gcc -c set_ev.c
$&amp;gt;ifort tes_set_ev.f90 set_ev.o -o tes_set_ev
$&amp;gt;./tes_set_ev
 Before calling c void: -&amp;gt;||&amp;lt;-
 After calling c void: -&amp;gt;|Hey, what's up!|&amp;lt;-
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2015 18:21:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053039#M115645</guid>
      <dc:creator>rudi-gaelzer</dc:creator>
      <dc:date>2015-10-06T18:21:43Z</dc:date>
    </item>
    <item>
      <title>Why not</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053040#M115646</link>
      <description>&lt;P&gt;Why not&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;INTERFACE
&amp;nbsp;&amp;nbsp; function setenv(name,value,overwrite) bind(C,name='setenv')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use ISO_C_BINDING
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; implicit none
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INT) setenv
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; character(KIND=C_CHAR), intent(in) :: name(*)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; character(KIND=C_CHAR), intent(in) :: value(*)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INT), value :: overwrite
&amp;nbsp;&amp;nbsp; end function setenv
END INTERFACE
&lt;/PRE&gt;

&lt;P&gt;and then invoke setenv() directly?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2015 20:05:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053040#M115646</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-06T20:05:52Z</dc:date>
    </item>
    <item>
      <title>Quote:Repeat Offender wrote:</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053041#M115647</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Repeat Offender wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Why not&lt;/P&gt;

&lt;PRE class="brush:fortran;"&gt;INTERFACE
&amp;nbsp;&amp;nbsp; function setenv(name,value,overwrite) bind(C,name='setenv')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use ISO_C_BINDING
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; implicit none
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INT) setenv
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; character(KIND=C_CHAR), intent(in) :: name(*)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; character(KIND=C_CHAR), intent(in) :: value(*)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; integer(C_INT), value :: overwrite
&amp;nbsp;&amp;nbsp; end function setenv
END INTERFACE
&lt;/PRE&gt;

&lt;P&gt;and then invoke setenv() directly?&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;I guess, you would have to make sure then, that you pass a proper '\0' terminated string, when calling from Fortran, otherwise C would have problem to detect, where the string ends.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 06:16:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053041#M115647</guid>
      <dc:creator>Bálint_A_</dc:creator>
      <dc:date>2015-10-07T06:16:27Z</dc:date>
    </item>
    <item>
      <title>Yep. Instead of passing "MY</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053042#M115648</link>
      <description>&lt;P&gt;Yep. Instead of passing "MY_ENV_VAR", one would pass 'MY_ENV_VAR'//C_NULL_CHAR or 'MY_ENV_VAR'//ACHAR(0). Normal stuff encountered when doing C interoperability. This is more commonplace in Windows where users seem to invoke Win32 API functions on more of a routine basis.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 12:52:04 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Setting-environment-variable/m-p/1053042#M115648</guid>
      <dc:creator>JVanB</dc:creator>
      <dc:date>2015-10-07T12:52:04Z</dc:date>
    </item>
  </channel>
</rss>

