J3/04-106 Date: 7 Dec 03 To: J3 From: Dan Nagle Subject: Executing an external program A functionality missing from the standard is a way to execute a program from within a Fortran program. Many vendors have added this feature to their compilers. Number: Title: EXECUTE_PROGRAM Submitted By: J3 Status: For Consideration References: Basic Functionality: Many times, programs must cooperate with other programs in order to produce the desired results. No way exists within the standard to do so, yet many vendors have added a "run this program" intrinsic procedure to their compilers. Rationale: On modern operating systems, programs may be a part of a pipe or may require that a file be produced in order to continue execution. How to do this is a FAQ in comp.lang.fortran and probably other forums as well. Sometimes, asynchronous execution is desired (for example, starting a program to read from a pipe), and sometimes synchronous execution is desired (for example, to produce a file for input). So the proposal should provide for both possibilities. However, executing external programs is processor-dependent, so the processor may return an error status if it can't fulfill a request. Estimated Impact: Many vendors have an intrinsic procedure to execute external programs already, standardizing the spelling and functionality will have a cost, but probably not too great as the proposal intends to allow processors to opt-out of any capability not supported. Detailed Specification: Add an EXECUTE_PROGRAM intrinsic procedure to the ISO_FORTRAN_ENV intrinsic module. EXECUTE_PROGRAM( CMD=, [ ASYNCHRONOUS=['YES'|'NO'], ] [ ID=, ] [ CMDSTAT=, ] [ CMDMSG= ] ) CMD= gives the command line to be executed. ASYNCHRONOUS= tells whether synchronous or asynchronous execution is requested. If absent, a value of 'NO' is assumed. The ID= gives a variable so the program may await the result of the external program via a WAIT statement. It is valid only if ASYNCHRONOUS= is present with the value 'YES'. The CMDSTAT= variable is zero to indicate successful completion or successful starting of the command line given. It is set to a processor dependent positive value if an error occurs. The CMDMSG= is the vendor's cheerful message detailing why the request failed. Example: CALL EXECUTE_PROGRAM( 'ls > list.out', CMDSTAT=mystat) GOT_LIST: IF( mystat == 0 )then OPEN( myunit, 'list.out') ELSE GOT_LIST WRITE( ERROR_UNIT, FMT= *) 'rant' ENDIF GOT_LIST History: