[英]Exchanging info between running C++ code and python script
I have a python script that is called inside a C++ program. 我有一个在C ++程序中调用的python脚本。 The python script creates a directory based on the current time, puts files in there, and then execution returns to C++. python脚本根据当前时间创建一个目录,将文件放入其中,然后执行返回到C ++。 I want to save a parameters file into the directory created in the python program. 我想将参数文件保存到python程序中创建的目录中。
I figure my options are: 我认为我的选择是:
I'm not sure how to do any of this. 我不知道该怎么做。 My python script is not embedded. 我的python脚本未嵌入。 I use 我用
std::string test = "python analyzeData2.py";
system(test.c_str());
to call a python script. 调用python脚本。
Any ideas how to do this? 任何想法如何做到这一点?
I'd go with option B -- return the location of the directory to c++ from python so it knows where to save the file. 我会选择选项B-从python返回目录的位置到c ++,以便它知道将文件保存在哪里。
If you plan on using system(), something like this: 如果计划使用system(),则如下所示:
char* dirname[64];
FILE* fin;
system("python analyzeData2.py > created.log");
fin = fopen("created.log", "r");
fgets(dirname, sizeof(dirname), fin);
fclose(fin);
/* dirname has contents of created.log */
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.