SYSTEMF()

Fortran version:

    INTEGER FUNCTION  SYSTEMF( COMMAND_STRING )
        CHARACTER*(*), INTENT(IN   ) :: COMMAND_STRING

C version: use system() instead

Summary:

SYSTEMF() is a Fortran wrapper around the system() C-library routine: it executes the specified command as though it had been typed in a shell (specifically, ksh), and returns the exit status of the command (0 for success; nonzero for failure), or (-1) if it can't find a shell under which it can execute the command.

Note that you can build up quite complex commands by the use of semicolons, pipes, redirects, etc.

Preconditions:

LEN( COMMAND_STRING ) is at most 4095

Fortran Usage:

    ...
    INTEGER     SYSTEMF
    EXTERNAL    SYSTEMF
    ...
    INTEGER     ISTAT
    ...
    !!  Command:  see if there are any files "/tmp/foo/*.ncf"
    !!  change directory to /tmp/foo, then see if there are
    !!  any files whose extension is ".ncf"
    !!  ("ls -1" says list one per line, the semicolon strings
    !!  the commands together into a compound command, and for "grep", 
    !!  we have to escape the period with a backslash (else it is a 
    !!  wild-card), and $ means at-end-of-line.)

    ISTAT = SYSTEMF( 'cd /tmp/foo ; ls -1 | grep "\.ncf$"' )

    IF      ( ISTAT .EQ. -1 ) THEN      !  could not execute "ksh":
        WRITE( *,* ) 
   &    'Error finding "ksh" to execute command'
    ELSE IF ( ISTAT .EQ. 0 ) THEN       !  "grep" found matches:
        WRITE( *,* ) 
   &    'Matches for ".ncf" were found'
    ELSE IF ( ISTAT .EQ. 1 ) THEN       !  "grep" did not find matches:
        WRITE( *,* ) 
   &    'No matches for ".ncf" found'
    ELSE                                !  "grep" had an I/O error:
        WRITE( *,* ) 
   &    'I/O errror ', ISTAT, ' encountered'
    END IF                              !  end nested IF's on values of ISTAT
    ...

C Usage:

use system() instead.


Previous: STR2INT and STR2REAL

Next: TRIMLEN

Up: Utility Routines

To: Models-3/EDSS I/O API: The Help Pages