When you start a process, it inherits many of the resources of the parent. This includes file handles, such as the standard input and standard output files. A child process also inherits the resources of the screen group, such as the mouse and video modes, and the environment variables of the parent process.

The call to DosExecPgm determines the command line and environment that the child process receives. The fourth and fifth parameters of the function are pointers to the command line and the environment, respectively. If these pointers are NULL, the child process receives nothing for a command line and only an exact duplicate of the environment of the parent process. The parent process can modify this information by creating a string (ending with two NULL characters) and passing the address of the string to the function. The command line string must include the name of the application, followed by a NULL character, and the command line arguments, followed by two NULL characters. Any number of arguments can be passed to the child process, as long as the argument string ends with two NULL characters.

The following code fragment passes to the child process the string "test -option1 -option2" as its command line:

    #define INCL_DOSPROCESS    /* Process and thread values */
    #include <os2.h>

    RESULTCODES resc;
    CHAR szFailName[CCHMAXPATH];

    CHAR szCommandLine[] = "test\0-option1 -option2\0";

    DosExecPgm(szFailName,          /* Object-name buffer  */
               sizeof(szFailName),  /* Length of buffer    */
               EXEC_SYNC,           /* Sync flag           */
               szCommandLine,       /* Argument string     */
               (PSZ) NULL,          /* Environment string  */
               &resc,               /* Address of result   */
               "test.exe");         /* Name of application */


[Back] [Next]