system

Passes a given string to the host environment to be executed by a command processor. This function is nonreentrant.

Format

#include  <stdlib.h>

int system  (const char *string);

Argument

string
A pointer to the string to be executed. If string is NULL, a nonzero value is returned. The string is a DCL command, not the name of an image. To execute an image, use one of the exec routines.

Description

This function spawns a subprocess and executes the command specified by string in that subprocess. The system function waits for the subprocess to complete before returning the subprocess status as the return value of the function.

The subprocess is spawned within the system call by a call to vfork. Because of this, a call to system should not be made after a call to vfork and before the corresponding call to an exec function.

For OpenVMS Version 7.0 and higher systems, if you include <stdlib.h> and compile with the _POSIX_EXIT feature-test macro set, then the system function returns the status as if it called waitpid to wait for the child. Therefore, use the WIFEXITED and WEXITSTATUS macros to retrieve the exit status in the range of 0 to 255.

You set the _POSIX_EXIT feature-test macro by using /DEFINE=_POSIX_ EXIT or #define _POSIX_EXIT at the top of your file, before any file inclusions.

Return Values
nonzero value  If string is NULL, a value of 1 is returned, indicating that the system function is supported. If string is not NULL, the value is the subprocess OpenVMS return status. 

Example

    #include <stdlib.h>
    #include <stdio.h>
    
    main ()
    {
     int status, fd;
    
     fd = creat ("system.test", 0);
     write (fd, "this is an example of using system", 34);
     close (fd);
    
     if system(NULL)
        {
          status = system ("DIR/NOHEAD/NOTRAIL/SIZE SYSTEM.TEST");
          printf ("system status = %d\n", status);
        }
     else
          printf ("system() not supported.\n");
    }
    


Previous Page | Next Page | Table of Contents | Index