title: Calling Python script from C++ and using its output
body: <p>I want to call a python script from C++ and wish to use the output .csv file generated by this script back into C++. I tried this in main():</p>
  
  <pre><code>std::string filename = "/home/abc/xyz/script.py";
  std::string command = "python ";
  command += filename;
  system(command.c_str());
  </code></pre>
  
  <p>This does call and execute the python script. </p>
  
  <p>The <code>print</code> commands in the Python are being executed. Things are being printed on the screen when the script is called. So far so good. However, it is not creating the .csv file (part of the same script).</p>
  
  <p>Example: I had a <code>training.csv</code> file with <strong>100 entries</strong>. I called the Python script, with little changes to the script so that the <code>training.csv</code> file <strong>now should contain only 50 entries instead of 100. It’s overwritten.</strong> However, no such thing happening. Rest of the commands in the script (<code>print</code>, etc) are working perfectly.</p>
  
  <p>The <code>training.csv</code> file is to be read with C++ normally using <code>fstream</code> and <code>getline</code>.</p>
  
  <p>Any idea how to do it (using Linux)?</p>