< c‎ | program
Defined in header <stdlib.h>
int system( const char *command );

Calls the host environment's command processor with command parameter. Returns implementation-defined value (usually the value that the invoked program returns).

If command is NULL pointer, checks if host environment has a command processor and returns nonzero value only if it the command processor exists.


[edit] Parameters

command - character string identifying the command to be run in the command processor. If NULL pointer is given, command processor is checked for existence

[edit] Return value

Implementation-defined value. If command is NULL, returns nonzero value only if command processor exists.

[edit] Notes

On POSIX systems, the return value can be decomposed using WEXITSTATUS and WSTOPSIG

Related POSIX function popen makes the output generated by command available to the caller.

[edit] Example

In this example there is a system call of the unix command ls -l >test.txt:

#include <stdlib.h>
int main(void) {
    system("ls -l >test.txt");
    return 0;

[edit] References

  • C11 standard (ISO/IEC 9899:2011):
  • The system function (p: 353-354)
  • C99 standard (ISO/IEC 9899:1999):
  • The system function (p: 317)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • The system function

[edit] See also

C++ documentation for system