# Fortran Wiki get_command_argument

## Description

Retrieve the number-th argument that was passed on the command line when the containing program was invoked.

## Standard

Fortran 2003 and later

Subroutine

## Syntax

call get_command_argument(number [, value, length, status])

## Arguments

• number - Shall be a scalar of type integer(4), number ≥ 0.
• value - Shall be a scalar of type character and of default kind.
• length - (Optional) Shall be a scalar of type integer(4).
• status - (Optional) Shall be a scalar of type integer(4).

## Return value

After get_command_argument returns, the value argument holds the number-th command line argument. If value can not hold the argument, it is truncated to fit the length of value. If there are less than number arguments specified at the command line, value will be filled with blanks. If number = 0, value is set to the name of the program (on systems that support this feature). The length argument contains the length of the number-th command line argument. If the argument retrival fails, status is a positiv number; if value contains a truncated command line argument, status is -1; and otherwise the status is zero.

## Example

program test_get_command_argument
integer :: i
character(len=32) :: arg

i = 0
do
call get_command_argument(i, arg)
if (len_trim(arg) == 0) exit

write (*,*) trim(arg)
i = i+1
end do
end program

## See also

category: intrinsics