Skip to content

[Flang] Intrinsic execute_command_line returns incorrect CMDSTAT when the command returns non-zero return code. #92929

@DanielCChen

Description

@DanielCChen

Consider the following code:

        integer :: e = 0
        integer :: c = 0
        character(90) :: msg = "No error!"

        print *, trim(msg)

        call execute_command_line("cat no", exitstat=e, cmdstat=c, &
          cmdmsg = msg)

        print *, e
        print *, c
        print *, trim(msg)
      end

Flang currently outputs

No error!
cat: no: No such file or directory
1
0
No error!

Executing cat no directly on the command line results return code 1. This would be considered as an error condition.
According to the standard,

CMDSTAT (optional) shall be a scalar of type integer with a decimal exponent range of at least four. It is an INTENT (OUT) argument. It is assigned the value −1 if the processor does not support command line execution, a processor-dependent positive value if an error condition occurs, or the value −2 if no error condition occurs but WAIT is present with the value false and the processor does not support asynchronous execution. Otherwise it is assigned the value 0.

CMDMSG (optional) shall be a default character scalar. It is an INTENT (INOUT) argument. If an error condition occurs, it is assigned a processor-dependent explanatory message. Otherwise, it is unchanged.

cmdstat should be assigned a positive value and the cmdmsg should also be assigned.

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorflang:runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions