User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdlib.h:system

Table of Contents

system

    #include <stdlib.h>
     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 <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;
}

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

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdlib.h/system.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz