python文件:
#!/usr/bin/python
#python.py
print 'python:hello world'
shell文件
#!/usr/bin/sh
#shell.sh
#chmod +x shell.sh
echo shell:hello world
python python.py
cpp文件
//callpython.cpp
#include <iostream>
#include <stdlib.h>
using namespace std;
int main () {
cout << "cpp:hello world" << endl;
system("./shell.sh");
return 0;
}
编译运行:
#g++ callpython.cpp -o callpython
#./callpython
运行结果:
cpp:hello world
shell:hello world
python:hello world
本文介绍了一个跨语言调用的简单示例,演示了如何从C++代码中调用Shell脚本,再由Shell脚本调用Python脚本,实现了不同编程语言间的交互与数据传递。
8011

被折叠的 条评论
为什么被折叠?



