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():
std::string filename = "/home/abc/xyz/script.py";
std::string command = "python ";
command += filename;
system(command.c_str());
This does call and execute the python script.
The print
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).
Example: I had a training.csv
file with 100 entries. I called the Python script, with little changes to the script so that the training.csv
file now should contain only 50 entries instead of 100. It’s overwritten. However, no such thing happening. Rest of the commands in the script (print
, etc) are working perfectly.
The training.csv
file is to be read with C++ normally using fstream
and getline
.
Any idea how to do it (using Linux)?