system
int system ( const char * command ); | stdlib.h |
cplusplus.com |
Execute command.
Invokes command interpreter to execute a command. Once terminated, the interpreter
gives back control to the program returning an int value.
Parameters.
Return Value.
If a command was successfully executed the command interpreter returns an
adequate value; generally 0 indicates that the action performed
by the command interpreter terminated with no errors.
A return value of -1 indicates an error, and global variable errno
is set to one of the following errors:
value description ENOENT Command interpreter not found ENOEXEC Command interpreter is not executable ENOMEM Error allocating memory for the process E2BIG Argument list too big
Portability.
Defined in ANSI-C.
Return value and possible errno values are system dependent.
Example.
/* system example : DIR */
#include <stdio.h>
#include <stdlib.h>
main ()
{
int i;
puts ("Trying to execute command DIR");
i = system ("dir");
if (i==-1) puts ("Error executing DIR");
else puts ("Command successfully executed");
return 0;
}
See also.
atof,
strtol,
strtoul