Running shell commands by C++
#include <iostream>
#include <stdio.h>
#include <stdlib.h> using namespace std;
string cmdinput;
string GetStdoutFromCommand(string cmd) { string data;
FILE * stream;
const int max_buffer = 256;
char buffer[max_buffer];
cmd.append(" 2>&1"); stream = popen(cmd.c_str(), "r");
if (stream) {
while (!feof(stream))
if (fgets(buffer, max_buffer, stream) != NULL) data.append(buffer);
pclose(stream);
}
return data;
} int main (){
cout << "Enter your command:" << endl;
string cmdinput;
getline (cin, cmdinput);
cout << "Your command was '" << cmdinput << "'" << endl;
string com = GetStdoutFromCommand(cmdinput);
cout << "Command: " << com << endl; return 0;
}
in this way you can easy get the output string of your input command in C++
refer to http://www.cplusplus.com/forum/unices/144187/
Running shell commands by C++的更多相关文章
- Testing shell commands from Python
如何测试shell命令?最近,我遇到了一些情况,我想运行shell命令进行测试,Python称为万能胶水语言,一些自动化测试都可以完成,目前手头的工作都是用python完成的.但是无法从Python中 ...
- Run Shell Commands in Python
subprocess.call This is the recommended way to run shell commands in Python compared with old-fashio ...
- Frequently Used Shell Commands
[Common Use Shell Commands] 1.ps aux:查看当前所有进程 ,以用户名为主键.可以查看到 USER.PID.COMMAND(binary所有位置) 2.netstat ...
- Running multiple commands in one line in shell
You are using | (pipe) to direct the output of a command into another command. What you are lookin ...
- 在R中运行Shell命令脚本(Call shell commands from R)
aaa.R Args <- commandArgs()cat("Args[1]=",Args[1],"\n")cat("Args[2]=&quo ...
- mysql 使用 informatin_schema tables 创建 shell commands
SELECT CONCAT("mysqldump -uroot -p ", TABLE_SCHEMA, " ", TABLE_NAME, " > ...
- Hadoop FS shell commands
命令格式:hadoop fs -command -option args appendToFileUsage: hadoop fs -appendToFile <localsrc> ... ...
- echo shell commands as they are executed
http://stackoverflow.com/questions/2853803/in-a-shell-script-echo-shell-commands-as-they-are-execute ...
- Shelled-out Commands In Golang
http://nathanleclaire.com/blog/2014/12/29/shelled-out-commands-in-golang/ Shelled-out Commands In Go ...
随机推荐
- 并发编程从零开始(十四)-Executors工具类
并发编程从零开始(十四)-Executors工具类 12 Executors工具类 concurrent包提供了Executors工具类,利用它可以创建各种不同类型的线程池 12.1 四种对比 单线程 ...
- SpringBoot教程(学习资源)
SpringBoot教程 SpringBoot–从零开始学SpringBoot SpringBoot教程1 SpringBoot教程2 --SpringBoot教程2的GitHub地址 SpringB ...
- linux下测试读写
1.测/目录所在磁盘的纯写速度: time dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file 2.测/目录所在磁盘的纯读速度: time dd if ...
- 什么是SimpleNVR流媒体服务器软件?
SimpleNVR是一款新兴流媒体服务器应用软件,占用内存少,无插件.跨平台,应用非常广泛,操作简单易上手,同时还支持一键观看,十分便捷.另外,跟其他一般流媒体服务器不同,SimpleNVR支持开发者 ...
- robot_framewok自动化测试--(5)Screenshot 库
Screenshot 库 Scrennshot 同样为 Robot Framework 标准类库,我们只将它提供的其它中一个关键字"TakeScreenshot",它用于截取到当前 ...
- Kali-Linux 2020如何设置中文
话不多说,直接上步骤 首先,想要修改系统默认语言普通用户是办不到的,这个时候就需要切换为root用户在终端输入 sudo su(切换用户指令,后面不加用户名就默认切换为root) 输入管理员密码后就像 ...
- 好久没更新了,我回来了---Ajax
1.Ajax概念以及优势 * 什么是AJAX * AJAX(Asynchronous JavaScript And XML),(异步 JavaScript 和 XML),中文名:阿贾克斯.是指一种创建 ...
- 使用pmml跨平台部署机器学习模型Demo——房价预测
基于房价数据,在python中训练得到一个线性回归的模型,在JavaWeb中加载模型完成房价预测的功能. 一. 训练.保存模型 工具:PyCharm-2017.Python-39.sklearn2 ...
- 微服务改造之Openfeign的强化插件
在接触 Spring Cloud 这套框架之前,笔者使用的一直是Dubbo.在转型到Spring Cloud 后,发现了一个很郁闷的问题.Spring Cloud 中的 Openfeign,相比于 D ...
- 【Azure 应用服务】App Service 无法连接到Azure MySQL服务,报错:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
问题描述 App Service使用jdbc连接MySQL服务,出现大量的 Communications link failure: com.mysql.cj.jdbc.exceptions.Com ...