Header File
stdlib.h
Category
Process Control Routines
Prototype
int system(const char *command);
int _wsystem(const wchar_t *command);
Description
Issues an operating system command.
system invokes the operating system command processor to execute an operating system command, batch file, or other program named by the string command, from inside an executing C program.
To be located and executed, the program must be in the current directory or in one of the directories listed in the PATH string in the environment.
The COMSPEC environment variable is used to find the command processor program, so it need not be in the current directory.
Return Value
If command is a NULL pointer, system returns nonzero if a command processor is available.
If command is not a NULL pointer, system returns 0 if the command processor was successfully started.
If an error occurred, a -1 is returned and errno is set to one of the following:
ENOENT |
Path or file function not found |
ENOEXEC |
Exec format error |
ENOMEM |
Not enough memory |
Example
#include <stdlib.h> #include <stdio.h> int main(void) { printf("About to spawn a command-line program.\n"); system("dir"); return 0; }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
system |
+ |
+ |
|
|
_wsystem |
|
NT only |
|
|
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|