Sun Studio 12: Fortran Library Reference

1.4.50 system: Execute a System Command

The function is called by:

INTEGER*4 system

status = system( string )




String containing command to do 

Return value 



Exit status of the shell executed. See wait(2) for an explanation of this value.

Example: system():

       character*8 string / ’ls s*’ /
       INTEGER*4 status, system
       status = system( string )
       if ( status .ne. 0 ) stop ’system: error’

The function system passes string to your shell as input, as if the string had been typed as a command. Note: string cannot be longer than 1024 characters.

If system can find the environment variable SHELL, then system uses the value of SHELL as the command interpreter (shell); otherwise, it uses sh(1).

The current process waits until the command terminates.

Historically, cc developed with different assumptions:

The system function flushes all open files:

The functions sh(3f) and system(3f) pass the argument string to a shell for execution. They convert the argument string from a Fortran character value to a C string value and pass it to the C routine system(3c). The routines sh(3f) and system(3f) differ in that system flushes the Fortran I/O buffers before calling the C routine system, while sh does not. Flushing the buffers can take significant time, and so, if any Fortran output is irrelevant to the result of the call, the routine sh is preferred over the routine system.

See also: execve(2), wait(2), and system(3).

The system() function is not MT-safe. Do not call it from multithreaded or parallelized programs.