cess receives as its environment string a copy of the environ
ment string used by the program that called it.
When mode 0 of Pexec() is used, the call loads the new
program, sets up its basepage, passes the arguments and en
vironment to it, and executes it. This child process, as it's
called, inherits the parent's standard file descriptors (handles
0-5; see Chapter 6 for more information on standard file han
dles). When the program ends, the call returns an exit code
from the program (if it passes one) in status. A negative
value in status indicates that the program could not be exe
cuted (because there wasn't enough memory to run it, or
some other reason). Error returns in status are negative long-
words, while return codes passed from the child process are
word length, with Os in the upper 16 bits of the longword.
Modes 3 and 4 split the functions of mode 0. Mode 3 of
Pexec() takes the same parameters as mode 0, but it just
loads the specified file, sets up its basepage, and returns a
pointer to the basepage in status. It does not execute the pro
cess. To run the program after it has been loaded with mode
3, you may use mode 4 of Pexec(). This mode uses the
pointer to the program's basepage that was returned by
mode 3 as its only parameter. This pointer is passed in com
mand. The last mode of Pexec(), mode 5, allocates the largest
free block of memory and creates most of a basepage for it.
Some basepage values, such as the size and address of text,
data, and BSS section, obviously can not be filled in.
Program 5-3 shows how to load and execute a separate
program from within the current one. It demonstrates the
basic principal used by command shell-type programs, which
provide an MS-DOS command-line environment for the ST.
Program 5-3. GPEXEC.C
*•*********«******«***************************/
*
*
GPEXEC.C
*
*
Demonstrates use of the GEMDOS
*
Pexecf) function to run other programs.
*
I include <osbind.h>
char file[81];
/ *
char buffer[83]; /* input line buffer
char 'command;
102
CHAPTER 5
/ *
For GEMDOS macro definitions
file name buffer */
/ *
pointer to command tail string
*/
*/
* /
*/
* /
*/
* /
* /
* /