system() Execute DOS Command
#include <process.h> Required for declarations only
#include <stdlib.h> Use either process.h or stdlib.h
int system(string);
char *string; Command to be executed
system() passes 'string' to the command interpreter COMMAND.COM to be
executed. This executes 'string' as if it were typed in at the DOS
prompt.
Returns: 0 if the command is successfully executed. -1 indicates
an error and 'errno' (defined in <stdlib.h>) is set to
one of the following values (defined in <errno.h>):
E2BIG The argument list for the command exceeds
128 bytes.
ENOENT COMMAND.COM cannot be found.
ENOEXEC COMMAND.COM is not an executable file.
ENOMEM Not enough memory.
Notes: system() uses the COMSPEC and PATH environment variables
to locate COMMAND.COM.
-------------------------------- Example ---------------------------------
The following statements send a directory listing to the file
"dir.txt":
#include <process.h> /* for 'system' */
#include <stdio.h> /* for 'printf' */
#include <stdlib.h> /* for 'errno' */
#include <errno.h> /* for 'ENOENT' and 'ENOMEM' */
main()
{
int result;
result = system("dir >> dir.txt");
if (result == -1)
if (errno == ENOENT)
printf("can't find COMMAND.COM\n");
else if (errno == ENOMEM)
printf("not enough memory\n");
else
printf("error #%d executing system command\n",errno);
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster