c++调用shell & shell调用python
来源:互联网 发布:http默认端口号 编辑:程序博客网 时间:2024/06/16 07:28
- 本文主要实现c++调用shell & shell调用python
- c++/cpp2shell.cpp
- 向shell脚本传入参数,并获得返回值
#include <stdlib.h>#include <iostream>using namespace std;string exec(const char* cmd) { FILE* pipe = popen(cmd, "r"); if (!pipe) return "ERROR"; char buffer[128]; std::string result =""; while(!feof(pipe)) { if(fgets(buffer, 128, pipe) != NULL) result += buffer; } pclose(pipe); return result;}int main(){ char pic[3][16] = {"6418.jpg","2991.jpg","7319.jpg"}; string shell_str = "sh shell2python.sh "; for(int i=0;i<3;i++){ string pic_name = pic[i]; string exec_str = shell_str + pic_name; string result = exec(exec_str.c_str()); printf(result.c_str()); } return 0;}
- shell/shell2python.sh
#!/bin/bash a=$(/usr/local/bin/python /home/szx/test/test_captcha.py $1 2>&1)b=${a:0-4:4} #只取最后4个字符echo $b
- python/test_captcha.py(部分)
import sys #...(省略大部分代码)def captcha_test_once(image_name): image = Image.open(image_name) image = np.array(image) image = convert2gray(image) image = image.flatten() / 255 predict_text = crack_captcha(image) sys.exit(predict_text)captcha_test_once(sys.argv[1])
阅读全文
0 0
- 笔记:python 调用 shell 和 C
- c++调用shell & shell调用python
- python调用shell
- Python 调用shell脚本
- python调用shell
- python调用shell命令
- python中调用shell
- python调用Shell脚本
- Python调用shell命令
- python调用Shell脚本
- python调用shell脚本
- python调用shell命令
- python调用shell
- python调用shell命令
- python调用shell总结
- python调用shell命令
- shell调用python
- python调用shell脚本
- 如何控制Java代码向数据库中插入数据
- Refletion2017.9.4
- 数据结构线性表
- TOPGP5.3:combobox动态下拉
- HDU 6186 前缀后缀
- c++调用shell & shell调用python
- 弱鸡,C# System.Timers.Timer测试
- CodeForces 431# div.2 A Odds and Ends 暴力 贪心
- virtual box虚拟机安装+ubuntu14.04系统安装+GCC4.8编译器安装
- 城市正视图,紫书P132UVa221
- HDU —2012 素数判定
- python 模拟链表
- 简单的分割法
- javax.imageio.IIOException: Can't create output stream解决方法