Manual Reference Pages  - execute_command_line (3fortran)

NAME

EXECUTE_COMMAND_LINE(3) - [SYSTEM:PROCESSES] Execute a shell command

SYNOPSIS

call execute_command_line( & & command [,wait] [,exitstat] [,cmdstat] [,cmdmsg] )

         subroutine execute_command_line(command,wait,exitstat,cmdstat,cmdmsg)

character(len=*),intent(in) :: command logical,intent(in),optional :: wait integer,intent(inout),optional :: exitstat integer,intent(inout),optional :: cmdstat character(len=*),intent(inout),optional :: cmdmsg

CHARACTERISTICS

o COMMAND is a default character scalar
o WAIT is a default logical scalar. If WAIT is present with the
o EXITSTAT is an integer of the default kind. It must be of a kind with at least a decimal exponent range of 9.
o CMDSTAT is an integer of default kind The kind of the variable must support at least a decimal exponent range of four.
o CMDMSG is a character scalar of the default kind.

DESCRIPTION

For EXECUTE_COMMAND_LINE(3) the COMMAND argument is passed to the shell and executed. (The shell is generally SH(1) on Unix systems, and cmd.exe on Windows.) If WAIT is present and has the value .false., the execution of the command is asynchronous if the system supports it; otherwise, the command is executed synchronously.

The three last arguments allow the user to get status information. After synchronous execution, EXITSTAT contains the integer exit code of the command, as returned by SYSTEM. CMDSTAT is set to zero if the command line was executed (whatever its exit status was). CMDMSG is assigned an error message if an error has occurred.

Note that the system call need not be thread-safe. It is the responsibility of the user to ensure that the system is not called concurrently if required.

When the command is executed synchronously, EXECUTE_COMMAND_LINE returns after the command line has completed execution. Otherwise, EXECUTE_COMMAND_LINE returns without waiting.

Because this intrinsic is making a system call, it is very system dependent. Its behavior with respect to signaling is processor dependent. In particular, on POSIX-compliant systems, the SIGINT and SIGQUIT signals will be ignored, and the SIGCHLD will be blocked. As such, if the parent process is terminated, the child process might not be terminated alongside.

One of the most common causes of errors is that the program requested is not in the search path. You should make sure that the program to be executed is installed on your system and that it is in the system’s path when the program calls it. You can check if it is installed by running it from the command prompt. If it runs successfully from the command prompt, it means that it is installed, and so you should next check that it is in the search path when the program executes (usually this means checking the environment variable PATH).

OPTIONS

o COMMAND : the command line to be executed. The interpretation is programming-environment dependent.
o WAIT : If WAIT is present with the value .false., and the processor supports asynchronous execution of the command, the command is executed asynchronously; otherwise it is executed synchronously.

When the command is executed synchronously, EXECUTE_COMMAND_LINE(3) returns after the command line has completed execution. Otherwise, EXECUTE_COMMAND_LINE(3) returns without waiting.

o EXITSTAT : If the command is executed synchronously, it is assigned the value of the processor-dependent exit status. Otherwise, the value of EXITSTAT is unchanged.
o CMDSTAT : If an error condition occurs and CMDSTAT is not present, error termination of execution of the image is initiated.

It is assigned the value -1 if the processor does not support command line execution, a processor-dependent positive value if an error condition occurs, or the value -2 if no error condition occurs but WAIT is present with the value false and the processor does not support asynchronous execution. Otherwise it is assigned the value 0.

o CMDMSG : If an error condition occurs, it is assigned a processor-dependent explanatory message. Otherwise, it is unchanged.

EXAMPLES

Sample program:

    program demo_exec
    implicit none
       integer :: i

call execute_command_line("external_prog.exe", exitstat=i) print *, "Exit status of external_prog.exe was ", i

call execute_command_line("reindex_files.exe", wait=.false.) print *, "Now reindexing files in the background" end program demo_exec

STANDARD

Fortran 2008

SEE ALSO

GET_ENVIRONMENT_VARIABLE(3)

fortran-lang intrinsic descriptions (license: MIT) @urbanjost


Nemo Release 3.1 execute_command_line (3fortran) March 23, 2024
Generated by manServer 1.08 from 8fabfb85-030f-4393-9b0b-3720199d35e3 using man macros.