新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么在c中運(yùn)行程序
C語言中運(yùn)行python程序

C語言使用popen/system或者直接以系統(tǒng)調(diào)用級fork+exec來運(yùn)行python程序也是一種混編的手段了。
舉例如下,Python代碼如下
#!/usr/bin/env python # test.py import sys x = int(sys.argv[1]) print x*x
C語言代碼如下
/* test.c */ #include#include int main() { FILE *f; char s[1024]; int ret; f = popen("./test.py 99", "r"); while((ret=fread(s,1,1024,f))>0) { fwrite(s,1,ret,stdout); } fclose(f); return 0; }
測試如下
$ gcc test.c $ ./a.out 9801
本文題目:創(chuàng)新互聯(lián)Python教程:python怎么在c中運(yùn)行程序
URL鏈接:http://m.5511xx.com/article/dhjhihs.html


咨詢
建站咨詢
