title: how to check system() result
body: <p>How should I check if the system command was run successfully and it didn't return error?
  According to <a href="http://msdn.microsoft.com/en-us/library/277bwbdz%28v=vs.71%29.aspx" rel="nofollow">MSDN Library</a>, there are multiple cases. I couldn't be sure if the following snippet is correct.</p>
  
  <pre><code>char buffer[100];
  int ret_val;
  strcpy(buffer, "copy *.txt ");
  strcat(buffer, path);
  ret_val = system(buffer);
  if(0 != ret_val)
  {
    perror("There was an error");
  }
  else
  {
    printf("The command was run successfully.");
  }
  </code></pre>
  
  <p>Return Value</p>
  
  <p>If command is NULL and the command interpreter is found, returns a nonzero value. If the command interpreter is not found, returns 0 and sets errno to ENOENT. If command is not NULL, system returns the value that is returned by the command interpreter. It returns the value 0 only if the command interpreter returns the value 0. A return value of – 1 indicates an error, and errno is set to one of the following values:</p>