title: Passing a $_POST variable in PHP to a C++ program run by exec() function
body: <p>I have the following C++ program for testing purposes:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
  int len;
  char* lenstr = getenv("CONTENT_LENGTH");
  
  if (lenstr != NULL &amp;&amp; (len = atoi(lenstr)) != 0)
  {
      char* post_data = new char[len];
      fgets(post_data, len + 1, stdin);
      cout &lt;&lt; post_data &lt;&lt; endl;
      delete post_data;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This simply ought to get an environment variable and display it on the screen. The PHP file from which I want to invoke this function is as follows (I call this via AJAX):</p>
  
  <pre><code>&lt;?php
  $sent = $_POST['source'];
  if ($sent != "")
  {
      echo exec("test.exe");
  }
  else
      echo "Please enter text";
  ?&gt;
  </code></pre>
  
  <p>Now, the question is, how do I get $sent to be fed into the C++ program as an argument to be processed in there? I've done some research on the Internet and also here on SO, but so far I keep failing.</p>