HELPLIB.HLB  —  CRTL  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);

1  –  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.

2  –  Description

    The system 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 (described in the wait* routines) 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.

3  –  Return Value

    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.

4  –  Example

        #include <stdlib.h>
        #include <stdio.h>
        #include <unistd.h>     /* write, close */
        #include <fcntl.h>      /* Creat */

        main()
        {
            int status,
                fd;

            /* Creat a file we are sure is there        */

            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");
        }

    Running this example program produces the following result:

    DISK3$:[JONES.CRTL.2059.SRC]SYSTEM.TEST;1
                               1
    system status = 1
Close Help