【发布时间】:2016-06-07 17:26:55
【问题描述】:
我正在尝试利用两个不同脚本的各个方面并将它们用于单个 C++ 程序(使用 Ubuntu)。我遇到的问题是其中一个脚本是用 C++ 编写的,另一个是用 python 编写的。我一直在尝试使用 Python.h 库来完成此操作,但是(对于编程来说是相当新的),我找不到任何可以让我在 C++ 中打开 python 文件的资源。有人有什么建议吗?
例如,我想做如下的事情:
#include <python2.7/Python.h>
//include other stuff
int main (int argc, char *argv[])
{
//open python script here
//use result from python script here
}
谢谢!
【问题讨论】:
-
查找
system或popen系统调用。man 2 system或man 2 popen -
仅供参考,C++ 不被视为脚本,因为它是一种编译语言。此外,大型 Python 脚本的调用/启动方式与小型 Python 脚本相同。您收到的其他建议很好 -
system()如果您对收集 Python 脚本的输出不感兴趣,popen()如果您愿意。
标签: python c++ python-2.7 unix ubuntu