Syntax
#include <stdlib.h> int system(char *string);Description
system passes the command string to a command processor to be run. The command processor specified in the COMSPEC environment variable is first searched for. If it does not exist or is not a valid executable file, the default command processor, CMD.EXE, is searched for in the current directory and in all the directories specified in the PATH environment variable.
If the specified command is the name of an executable file created from a C program, full initialization and termination are performed, including automatic flushing of buffers and closing of files. To pass information across a system function, use a method of interprocess communication like pipes or shared memory.
You can also use system to redirect standard streams using the redirection operators (the angle brackets), for example:
rc = system("cprogram < in.file");
The defaults for the standard streams will be whatever the standard streams are at the point of the system call; for example, if the root program redirects stdout to file.txt, a printf call in a C module invoked by a system call will append to file.txt. Returns
If the argument is a null pointer, system returns nonzero if a command processor exists, and 0 if it does not. system returns the the return value from the command processor if it is successfully called. If system cannot call the command processor successfully, the return value is -1 and errno is set to one of the following values: compact break=fit.
Value
This example shows how to use system to execute the OS/2 command dir c:\ :
#include <stdlib.h> int main(void) { int rc; rc = system("dir c:\\"); return rc; /* The output should be a listing of the root directory on the c: drive */ }Related Information