GET_COMMAND_ARGUMENT intrinsic subroutine

Standard: F77 F90 F95 F2003 F2008 F2018 Example program



NUMBER : scalar Integer, 16 bits or larger, Intent(In);
VALUE : scalar default Character, Intent(Out);
LENGTH : scalar Integer, 16 bits or larger, Intent(Out);
STATUS : scalar Integer, 16 bits or larger, Intent(Out);
ERRMSG : scalar default Character, Intent(Out).

Prior to Fortran 2018, the Integer arguments had to be of default kind.


This intrinsic subroutine retrieves the command argument for the current execution identified by NUMBER. Argument 0 is the “command name”, this might be a simple name, the full path name of the executable program (or anything in between), or blank if the command name cannot be determined. Remaining arguments, up to the number specified on the command line, are number 1 to COMMAND_ARGUMENT_COUNT() from left to right. If NUMBER is less than zero or greater than COMMAND_ARGUMENT_COUNT() an error will be produced.

If VALUE is present, it is assigned the value of the command argument as if by normal character assignment.

If LENGTH is present, it is assigned the length of the command argument (before its assignment to VALUE). This may be used to allocate a VALUE variable large enough to receive the full value of the argument.

If STATUS is present, it is assigned the value −1 if VALUE was present but is shorter than the command argument length, a positive value if an error occurs (for example, if NUMBER is out of range), and zero otherwise.

If an error occurs and ERRMSG is present, ERRMSG is assigned an explanatory message. Otherwise, ERRMSG is unchanged.


COMMAND_ARGUMENT_COUNT intrinsic function, GET_COMMAND intrinsic subroutine