Name
system - Executes an operating system command.
Syntax
#include <process.h>
#include <stdlib.h>
int system(string)
char *string;
Description
The system function passes string to the command interpreter
and executes the string as an operating system command. The
system function refers to the COMSPEC and PATH environment
variables that locate the command-interpreter file
COMMAND.COM in DOS or CMD.EXE in OS/2. If string is a
pointer to a NULL string, the function simply checks to see
whether the command interpreter exists or not.
Return Value
If string is a pointer to a NULL string and the command
interpreter is found, the function returns a nonzero value.
If the command interpreter is not found, it returns the
value 0 and sets errno to ENOENT. If string is not NULL, the
system function returns the value 0 if the command
interpreter is successfully started.
A return value of -1 indicates an error, and errno is set to
one of the following values:
Value Meaning
E2BIG In DOS, the argument list exceeds 128
bytes, or the space required for the
environment information exceeds 32K.
In OS/2, the argument list and the
space required for environment
information combined exceed 32K.
ENOENT The command interpreter cannot be
found.
ENOEXEC The command-interpreter file has an
invalid format and is not executable.
ENOMEM Not enough memory is available to
execute the command; or the available
memory has been corrupted; or an
invalid block exists, indicating that
the process making the call was not
allocated properly.
See Also
exec(DOS), exit(DOS), _exit(DOS), spawn(DOS)
Example
#include <process.h> #include <stdlib.h>
int result;
main() {
/* Place version number in "result.log"*/
result = system("ver >>result.log");
/* Type "result.log" to the screen */
result = system("type result.log"); }
This program uses the system function to place the DOS
version number in a file named result.log and then displays
result.log on the screen.
(printed 6/18/89)