我想从 c 运行一个 python 脚本。我试过它编译成功但它给出错误“python 不被识别为内部或外部命令、可运行的程序或批处理文件”。
#include <iostream>
using namespace std;
// main() is where program execution begins.
int main()
{
std::string filename = "hi.py";
std::string command = "python ";
command += filename;
FILE* in = popen(command.c_str(), "r");
pclose(in);
return 0;
}
最佳答案
您想使用 python 可执行文件的完整路径,例如:
std::string command = "/usr/bin/python ";
关于python - 从 C++ 运行 python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33526534/