get_command
- Date:
02-07-2023
NAME
get_command - Returns the entire command line that invoked the program
SYNOPSIS
call get_command ([command, length, istatus])
STANDARDS
Fortran 2008
DESCRIPTION
The get_command intrinsic subroutine returns the entire command line that invoked the application. The get_command accepts these optional arguments:
- command
The entire or truncated command line that invoked the program. If the command line cannot be ascertained, command is filled with blanks. This argument must be a scalar of type default character.
- length
The length of the command line contained in the command argument in bytes. If the length cannot be ascertained, zero is returned. This argument must be a scalar of type default integer.
- istatus
Returns the condition of the data contained in the command and length arguments. The following values are returned:
- 0
The command argument contains the entire command line and the value of length is valid.
- Positive nonzero value
The command argument is filled with blanks and length is zero because the command line could not be ascertained.
- -1
The command line contained in the command argument was truncated and length indicates the size of the truncated command line.
EXAMPLES
The following example can be inserted into your application to return the number of arguments passed to your application and the command line used to invoke it:
integer icmdargs, length, istatus
character(len=255) :: cmd
!get the number of command line arguments
icmdargs = command_argument_count()
print *,'number of command line arguments =',icmdargs
if ( icmdargs .ne. 0 ) then
call get_command ( cmd, length, istatus )
if ( istatus .eq. 0 ) then
print *,'invoking command =', cmd
else if ( istatus .gt. 0 ) then
print *,'command not returned'
else
print *,'command truncated, length, cmd =',length,cmd
endif
endif
end
SEE ALSO
get_command_argument(3i), get_environment_variable(3i), command_argument_count(3i)