get_command(3f) - [FORTRAN:INTRINSIC:SYSTEM ENVIRONMENT] Get the entire command line
Description
Syntax
Arguments
Return Value
Example
Standard
Class
See Also
Retrieve the entire command line that was used to invoke the program.
call get_command([command, length, status])
COMMAND - (Optional) shall be of type CHARACTER and of default kind. LENGTH - (Optional) Shall be of type INTEGER and of default kind. STATUS - (Optional) Shall be of type INTEGER and of default kind.
If COMMAND is present, stores the entire command line that was used to invoke the program in COMMAND. If LENGTH is present, it is assigned the length of the command line. If STATUS is present, it is assigned 0 upon success of the command, -1 if COMMAND is too short to store the command line, or a positive value in case of an error.
Note that what is typed on the command line is often processed by a shell. The shell often processes special characters and white space before passing it to the program. The processing can typically be turned off by turning off globbing or quoting the command line arguments with quote characters and/or changing the default field separators, but this should rarely be necessary.
Sample program:
program demo_get_command implicit none integer :: COMMAND_LINE_LENGTH character(len=:),allocatable :: COMMAND_LINE! get command line length call get_command(length=COMMAND_LINE_LENGTH)
! allocate string big enough to hold command line allocate(character(len=COMMAND_LINE_LENGTH) :: COMMAND_LINE)
! get command line as a string call get_command(command=COMMAND_LINE)
! JIC:: trim leading spaces just in case COMMAND_LINE=adjustl(COMMAND_LINE)
write(*,(a))COMMAND_LINE
end program demo_get_commandSample execution:
./test_get_command arguments on the command line to echo # using the bash shell ./test_get_command ./test_get_command arguments *><~[]!{}?"| on the command line to echo
[[Fortran 2003]] and later
Subroutine
[[get_command_argument]], [[command_argument_count]]
get_command (3) | March 18, 2019 |