用C++运行Python脚本

2024-04-27 02:25:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从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;
 }

Tags: 文件in脚本外部命令语言stringincludemain