标签:*** names process col status open bsp iostream path
1、c++编译程序
#include <iostream> using namespace std; int test() { int a = 10, b = 5; return a+b; } int main() { cout<<"---begin---"<<endl; int num = test(); cout<<"num="<<num<<endl; cout<<"---end---"<<endl; }
g++ -o main_run main.cpp
2、python3调用c++可执行文件
# python3 import subprocess import os main = "./main_run" if os.path.exists(main): rc, out = subprocess.getstatusoutput(main) print(‘rc = %d, \nout = %s‘ % (rc, out) ) print( ‘*‘*10 ) f = os.popen(main) data = f.readlines() f.close() print(data ) print( ‘*‘*10 ) os.system(main)
命令结果:
c_py$ python3 -u py_call_c.py
rc = 0, out = ---begin--- num=15 ---end--- ********** [‘---begin---\n‘, ‘num=15\n‘, ‘---end---\n‘] ********** ---begin--- num=15 ---end---
标签:*** names process col status open bsp iostream path
原文地址:https://www.cnblogs.com/xiaoniu-666/p/10932272.html