Namespaces
Variants
Views
Actions

Difference between revisions of "c/program/system"

From cppreference.com
< c‎ | program
(Copy-editing)
(More copy-editing)
Line 15: Line 15:
  
 
===Return value===
 
===Return value===
Implementation-defined value. If {{tt|command}} is {{lc|NULL}}, returns a nonzero value if and only if the command processor exists.
+
Implementation-defined value. If {{tt|command}} is a null pointer, returns a nonzero value if and only if the command processor exists.
  
 
===Notes===
 
===Notes===

Revision as of 00:52, 5 July 2017

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

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

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

Contents

Parameters

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

Return value

Implementation-defined value. If command is a null pointer, returns a nonzero value if and only if the command processor exists.

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.

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;
}

References

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

See also