title: How do I catch syntax error in unix system commands
body: <p>I am using function <code>popen</code> for executing the system commands. My code is fine to me when the format of syntax is correct. Suppose I gave a incorrect syntax to the <code>popen</code>, I didn't know how to say. <strong><em>There is an error in the syntax</em></strong>. Here I include the sample code and input.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  
  int main(int argc,char *argv[])
  {
  
      //correct syntax
      string sysCmd="awk -v FIELDWIDTHS=\"10 8 10 5\" '19970517&gt;=gensub(/(....)(....)/,\"\\\\2\\\\1\",1,$2){print $1}' awktst.txt";
  
      //Incorrect syntax- extra closing braces found
      //string sysCmd="awk -v FIELDWIDTHS=\"10 8 10 5\" '19970517&gt;=gensub(/(....)(....)/,\"\\\\2\\\\1\",1,$2)){print $1}' awktst.txt";
  
      FILE *in;
      in=popen(sysCmd.c_str(),"r");
      if(in==NULL)
      {
          cout&lt;&lt;"Error in System Cmd Processing "&lt;&lt;endl;
          return 0;
      }
  
      char *buff=NULL;
      size_t maloc=0;
  
      while(getline(&amp;buff, &amp;maloc, in) != EOF){
          cout&lt;&lt;buff;
          free(buff);
          buff=NULL;
      }
      pclose(in);
  
      return 0;
  }
  </code></pre>
  
  <p>Input Sample</p>
  
  <pre><code>Bharath   010619925,1,000,00  100
  Ragul     10302002  2,000.00  600
  Bala      11171993  3,000.00  500
  Arjun     05142003  4,000.00  400
  Vimal     06301997  5,000.00  100
  Ramesh    05171997  1,000.00  300
  Kamal     05151997  2,000.56  200
  Vinoth    04201997  3,000.00  500
  </code></pre>
  
  <p>How can I catch error exception when I run the code with incorrect syntax?</p>