title: How to find if command executed in exec command fails?
body: <p>I need to know that If I call a php script execution command through exec command and the script execution fails due to any reason say "file not found" , then how can I find it out.
  I have following command :</p>
  
  <pre><code>    $cmd="php testfile.php" ;
      $outputfile="testoutput.txt";
      exec(sprintf("%s &gt; %s 2&gt;&amp;1 &amp; echo $!", $cmd, $outputfile),$pidArr, $status);
  </code></pre>
  
  <p>exec command return -1 in case of error but in this case exec is executing successfully ie $status is coming 0 in my case but the "php testfile.php" command is failing, the output is getting in testoutput.txt. 
  But I need to know the way so that I can identify it after exec if the command is failed.
  I could think of the option of reading testoutput.txt and grep for fail or error word, but I dont think it is reliable.</p>
  
  <p>Thanks in advance!</p>