Name

system - execute a shell command

Library

libc.lib

Synopsis

  #include <stdlib.h>
  int system (const char *string);

Return values

The system function returns the exit status of the child process as returned by process exit reason or -1 if an error occurred when spawning a new process. It returns zero when a NULL is passed as its argument.

Detailed description

The system function spawns another process with the argument string. The calling process waits for the child process to finish executing.

If string is a NULL pointer, system will return non-zero to indicate that system is suporrted and zero if it is not supported.

The system function returns the exit status of the child process as returned by process’ exit reason or -1 if an error occurred when spawning a new process.


Examples

#include <stdlib.h> //system
#include <stdio.h> //printf
 
int main( void )
{
   int retVal = -1;
  
   printf( "Calling system()...\n" );
  
   /* helloworld.exe is an executable that just prints
    * "Hello world!" and it should be created before
    * executing this example code.
    */
   retVal = system("c:\\sys\\bin\\helloworld.exe");
   
   /* Print the return value of system() */
   printf( "system() returned: %d", retVal );
   
   return 0;
}


Output

Calling system()...
system() returned: -1


See also

popen

Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top