Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Exec Procedure
◄Summary► ◄Details► ◄Example► ◄Back►
Arguments
pathname String expression representing name of the child
process to be executed
command_line String expression representing the command line for
executing the child process
Description
The Exec procedure loads and runs a child process. It suspends the
parent process that called Exec. The arguments specify the program
to be run and the command line to pass to the program.
The pathname argument passes the name of the program to be executed,
which can be a base name with an extension or a fully qualified DOS
path name including drive letter and subdirectories. Exec assumes
the current directory if no directory is specified. The argument is
of type PathStr, defined in the Dos unit.
The command_line argument passes commands or options to pass to the
child process. These commands are the arguments that would be given
after the name of the program on the DOS command line. If the
program needs no arguments, pass an empty string. The argument is
of type ComStr, defined in the Dos unit.
Exec does not allocate memory for the child process. To ensure
enough memory, use the {$M} directive at the beginning of the
parent program. To leave room for the child process to load and
run, set the stack and heap to the minimum possible settings.
Exec does not save any interrupt handlers for the parent. To
protect existing vectors from interference by the child process,
call the SwapVectors procedure before and after calling Exec.
Use the DosExitCode function to obtain the exit code returned by
the child process.
To execute a DOS command as the child process, specify COMMAND.COM
as the pathname argument. Specify the desired DOS command as the
command_line argument, preceded by a /c switch, which is not
case-sensitive. The /c switch tells DOS that the COMMAND.COM being
run is another copy. For example, to see a listing of executable
files in the current directory:
Exec( 'COMMAND.COM', '/C DIR *.EXE' );
Exec reports error conditions in DosError. Possible error values
are 2, 8, 10, and 11:
Value Error
═════ ═══════════════════
2 File not found
8 Not enough memory
10 Invalid environment
11 Invalid format