title: How to get the exit code of program invoked by system call?
body: <p>For example, Program <em>a.out</em>:</p>
  
  <pre><code>int main()
  {
      return 0x10;
  }
  </code></pre>
  
  <p>Program <em>b.out</em>:</p>
  
  <pre><code>int main()
  {
      if(system("./a.out") == 0x10)
         return 0;
      else
         return -1;
  }
  </code></pre>
  
  <p>According to <a href="http://en.cppreference.com/w/cpp/utility/program/system" rel="nofollow">cppreference</a>, the return value of <code>system()</code> is <em>implementation-dependent</em>. Thus, the attempt of program b.out is obvious erroneous.</p>
  
  <p>In the case above, how can I get <code>0x10</code> instead of an undetermined value? 
  If system call is not the right tool, what's the proper way to do this?</p>