J3/04-329r3 To: J3 From: Dan Nagle Subject: Execute an external program Date: 2004 August 11 Most compilers have a means of executing an external program, however, the spellings vary (widely). This paper proposes edits to provide a standard syntax. The functionality intended is to require synchronous execution and, at the processor's choice, to allow asynchronous execution of the external program. The user specifies the choice intended by the WAIT dummy argument. A processor may choose to support both modes. Whether the processor chooses to use a command line interpreter is also unspecified. Doing so would allow some conveniences, including use of shell built-in commands, searching a path, filename wildcard expansion and file re-direction, but may not be available on all processors. Number: Title: EXECUTE_COMMAND_LINE Submitted By: J3 Status: For Consideration References: Basic Functionality: Add a procedure to ISO_FORTRAN_ENV to cause an external program to execute. Rationale: Most processors provide a means to execute an external program, but the syntax varies. Furthermore, some processors may support only synchronous execution of external programs, so this processor limitation must be taken into account. Some programs may want to execute another program to generate an input file or to operate jointly via a pipe, thus program control over synchronous versus asynchronous execution should be supplied to some extent. Estimated Impact: The impact was estimated by J3 at 167 as Small. Detailed Specification: Executes a command line externally to the program. Whether the command line is interpreted by a shell is unspecified. Require synchronous execution and allow asynchronous execution. If synchronous execution, allow recovery of the executed process exit status. Allow processor-dependent error conditions. Edits: See paper 04-327 regards possible renumbering of 13.8.2. These edits assume that paper passes. [360:33++] Add: "13.8.2.2.x EXECUTE_COMMAND_LINE( COMMAND, [ WAIT, EXITSTAT, CMDSTAT, CMDMSG ] ) *Description.* Execute the command line identified by the string COMMAND. The processor must support synchronous and may support asynchronous execution of the external program. *Class.* Subroutine. *Arguments.* COMMAND shall be of type default character and shall be a scalar. It is an INTENT(IN) argument. It identifies the command line to be executed. The interpretation is processor-dependent. WAIT shall be of type default logical and shall (optional) be a scalar. It is an INTENT(IN) argument. When present and true, EXECUTE_COMMAND_LINE returns after the indicated command line has completed execution. When present and false, EXECUTE_COMMAND_LINE returns after the indicated command line has started execution. When not present, the effect is as if present with a value of true. EXITSTAT shall be of type default integer and shall (optional) be a scalar. It is an INTENT(INOUT) argument. It shall not be present if WAIT is present with a value of false. If WAIT is present with a value of true, the value of EXITSTAT is the processor-dependent exit status of the command line, if available. Otherwise, the value is unchanged. CMDSTAT shall be of type default integer and shall (optional) be a scalar. It is an INTENT(OUT) argument. It is assigned the value zero if no error occurred during EXECUTE_COMMAND_LINE and assigned a processor-dependent positive value otherwise. If an error occurs and CMDSTAT is not present, execution of the program terminates. If the processor does not support the concept of command lines, the value is 1. CMDMSG shall be of type default character and shall (optional) be a scalar. It is an INTENT(INOUT) argument. It is assigned a processor-dependent error message if the value of the variable associated with the CMDSTAT argument indicates an error occurred. Otherwise, the value of CMDMSG is unchanged. History: Submitted as 04-106 at Meeting 167