EXECUTE_COMMAND_LINE

9.92 EXECUTE_COMMAND_LINE — Execute a shell command

Description:
EXECUTE_COMMAND_LINE runs a shell command, synchronously or asynchronously.

The COMMAND argument is passed to the shell and executed, using the C library's system call. (The shell is sh 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 function need not be thread-safe. It is the responsibility of the user to ensure that system is not called concurrently.

Standard:
Fortran 2008 and later
Class:
Subroutine
Syntax:
CALL EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG ])
Arguments:
COMMAND Shall be a default CHARACTER scalar.
WAIT (Optional) Shall be a default LOGICAL scalar.
EXITSTAT (Optional) Shall be an INTEGER of the default kind.
CMDSTAT (Optional) Shall be an INTEGER of the default kind.
CMDMSG (Optional) Shall be an CHARACTER scalar of the default kind.
Example:
program test_exec
  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 test_exec
Note:
Because this intrinsic is implemented in terms of the system function call, 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.
See also:
SYSTEM

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gfortran/EXECUTE_005fCOMMAND_005fLINE.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部