User Tools

Site Tools


c:stdlib.h:system

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdlib.h:system [2013/01/22 22:02] (current)
Line 1: Line 1:
 +
 +{{keywords>wiki library source code example reference}}
 +====== system ======
 +<code c>
 +    #include <stdlib.h>
 +     int system(const char *string);
 +</code>    
 +system calls a command on the shell
 +
 +===== system c code example =====  
 +<code c>
 +/* 
 + * system example code
 + * http://code-reference.com/c/stdlib.h/system
 + */
 +#include <stdio.h>
 +#include <stdlib.h>
 + 
 +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;
 +}
 +
 +</code>
 +
 +==== 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
 +
 +
 +
  
advertising
c/stdlib.h/system.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz