Skip to main content

Execute system/external command

We can call execute_command_line to execute external commands in a FORTRAN program:

src/27_exec_command.f90
PROGRAM MAIN
IMPLICIT NONE

INTEGER exit_code

! Execute system command
PRINT *, "Executing: ls"
CALL execute_command_line("ls")

PRINT *, "Executing: du -hs ."
CALL execute_command_line("du -hs .", exitstat=exit_code)

PRINT *, "Exit code: ", exit_code

END