Command-Line Execution

The execute_command_line() runs a shell command, either synchronously or asynchronously. The routine was introduced in Fortran 2008 and replaces the non-standard system().

call execute_command_line(command[, wait][, exitstat][, cmdstat][, cmdmsg])
Argument Type Description
command character Command to execute.
wait logical If .false., given command is run asynchronously (optional).
exitstat integer Exit code of the executed command (optional).
cmdstat integer Will be set to 0, if command was executed successfully (optional).
cmdmsg character Error message, if an error occured (optional).

The following example call FIGlet to output a text-banner of a given string. On FreeBSD, install FIGlet with:

# pkg install misc/figlet

The FIGlet executable will be run synchronously by default:

! example.f90
program main
    implicit none
    character(len=*), parameter :: STR = 'FORTRAN'

    call execute_command_line('figlet -f banner "' // STR // '"')
end program main

Compile and execute the example program with:

$ gfortran10 -o example example.f90
$ ./example
####### ####### ######  ####### ######     #    #     #
#       #     # #     #    #    #     #   # #   ##    #
#       #     # #     #    #    #     #  #   #  # #   #
#####   #     # ######     #    ######  #     # #  #  #
#       #     # #   #      #    #   #   ####### #   # #
#       #     # #    #     #    #    #  #     # #    ##
#       ####### #     #    #    #     # #     # #     #