[英]Run python script from C++
我想從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 ";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.