Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
C Library
cassert (assert.h)
cctype (ctype.h)
cerrno (errno.h)
cfloat (float.h)
ciso646 (iso646.h)
climits (limits.h)
clocale (locale.h)
cmath (math.h)
csetjmp (setjmp.h)
csignal (signal.h)
cstdarg (stdarg.h)
cstddef (stddef.h)
cstdio (stdio.h)
cstdlib (stdlib.h)
cstring (string.h)
ctime (time.h)
cstdlib (stdlib.h)
functions:
abort
abs
atexit
atof
atoi
atol
bsearch
calloc
div
exit
free
getenv
labs
ldiv
malloc
mblen
mbstowcs
mbtowc
qsort
rand
realloc
srand
strtod
strtol
strtoul
system
wcstombs
wctomb
functions (non-standard):
itoa
macros:
EXIT_FAILURE
EXIT_SUCCESS
MB_CUR_MAX
NULL
RAND_MAX
types:
div_t
ldiv_t
size_t


system

function
<cstdlib>
int system ( const char * command );

Execute system command

Invokes the command processor to execute a command. Once the command execution has terminated, the processor gives the control back to the program, returning an int value, whose interpretation is system-dependent.

The function call also be used with NULL as argument to check whether a command processor exists.

Parameters

command
C string containing the system command to be executed.

Return Value

The value returned when the argument passed is not NULL, depends on the running environment specifications. In many systems, 0 is used to indicate that the command was succesfully executed and other values to indicate some sort of error.
When the argument passed is NULL, the function returns a nonzero value if the command processor is available, and zero otherwise.

Portability

The behavior and return value are platform-dependent.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* system example : DIR */
#include <stdio.h>
#include <stdlib.h>
int main ()
{
  int i;
  printf ("Checking if processor is available...");
  if (system(NULL)) puts ("Ok");
    else exit (1);
  printf ("Executing command DIR...\n");
  i=system ("dir");
  printf ("The value returned was: %d.\n",i);
  return 0;
}


See also