Work around/support for execute_command_line pgfortran

Hi!

Do you provide a work around for the lack of support of execute_command_line in pgfortran?

This is supported in GCC, Intel and Cray Fortran compilers, here is a simple example:

program test
    use iso_fortran_env
    implicit none 
    integer(kind=int32)   :: st
    character(len=20)  :: msg
    call execute_command_line("echo 'hi there!1'")
    call execute_command_line("echo 'hi there!2'",cmdstat=st,cmdmsg=msg)
end program test

Here is the output of pgfortran:

% pgfortran test.f90
PGF90-S-0079-Keyword form of argument illegal in this context for cmdstat (test.f90: 7)
PGF90-S-0079-Keyword form of argument illegal in this context for cmdmsg (test.f90: 7)
  0 inform,   0 warnings,   2 severes, 0 fatal for test

Are you planning to add support for it?

For reference, here is a related (old) question:

Post from 2015

Thanks for your help!

Hect0r

Hi Hect0r,

Sorry, we haven’t implemented this F2008 feature as of yet, but it is on the road map and should be available in a release later this year.

The work-around on Linux would be to call “system”.

% cat system.F90
program test
    use iso_fortran_env
    implicit none
    integer(kind=int32)   :: st
    character(len=20)  :: msg
    call system("echo 'hi there!1'")
    call system("echo 'hi there!2'")
end program test

% pgfortran system.F90; a.out
hi there!1
hi there!2

Hope this helps,
Mat

Hey Mat,

Thanks for your reply, actually using system as a function gives the benefit of an status number if the command fails:

program test
    use iso_fortran_env
    implicit none 
    integer(kind=int32)   :: st ,system 
    st = system("echo hi1!;exit 10")
    print*,"status: ", st
    st = system("echo hi2!")
    print*,"status: ", st
end program test

Output:
% pgfortran workaround.f90; ./a.out 
hi1!
 status:          2560
hi2!
 status:             0

If I try a status by calling system as a subroutine I got a segmentation fault, here an example:

program test
    use iso_fortran_env
    implicit none 
    integer(kind=int32)   :: st
    call system("echo 'hi there!2'",st)
end program test

Output:
% pgfortran workaround.f90; ./a.out 
zsh: segmentation fault (core dumped)  ./a.out

Does this work around work as well for Windows?

If not, which work around works for Windows?, do you know of a OS independent work around?

Thanks,

Hect0r

Hi Hect0r,

“system” is a lib3f call that’s just a wrapper for the C “system” call.

Since it doesn’t have an interface, it uses F77 style calling conventions. Hence you can pass any number of arguments to the call and the compiler can’t check if it’s correct. Here, “system” is only expecting a single argument so it’s not surprising that calling it with an extra argument would cause unexpected behavior.

It does return the exit code from “system”, so using it as a function returning an integer would be how you want to capture the status.

See: https://www.pgroup.com/resources/docs/19.1/x86/fortran-ref-guide/index.htm#system

-Mat