{{keywords>wiki library source code example reference}}
====== system ======
#include
int system(const char *string);
system calls a command on the shell
===== system c code example =====
/*
* system example code
* http://code-reference.com/c/stdlib.h/system
*/
#include
#include
int main (void)
{
char * command = "uname -a";
int cmd = system( command );
if( cmd == -1 ) { printf( "Error while initalize system command.\n"); }
else if( cmd > 0 ) { printf( "command return value %d.\n", cmd ); }
else printf( "success\n" );
return 0;
}
==== Output ====
user@host:~$ ./system
Linux host 3.0.0-15-generic-pae #26-Ubuntu SMP Fri Jan 20 17:07:31 UTC 2012 i686 i686 i386 GNU/Linux
success