<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/92929>92929</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Intrinsic `execute_command_line` returns incorrect `CMDSTAT` when the command returns non-zero return code.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DanielCChen
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU2P4jgQ_TXmUuooOE0ghxxYaFZ96J7DsNrjyNiVxCvHjvzRH_vrVxVC08xAjxYhRU5elV_Vey6LEHRrEWu2-IMttjORYud8vRVWo9lsOrSzg1Pv9cbZoBV6iB1C44xxr9q2IJ1CVqxZvmX5mpX59B-XMP20jdiiB8IVa0BgxRa-xshrGNkJL2REz_iqyhmvTug-tCOecf7sAL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