1 Star 0 Fork 1

klose28/QtService

forked from tredy6t/QtService 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Command.h 986 Bytes
一键复制 编辑 原始数据 按行查看 历史
chenfei 提交于 2023-12-21 14:15 . Source files
#ifndef COMMAND_H
#define COMMAND_H
#include <stdio.h>
#include <string>
namespace Utils {
class CommandHelper {
public:
static std::string ExecCommand(const std::string& strCmd, int nCntFilterTag = 1)
{
std::string strOutput;
#ifdef WIN32
FILE* pFile = _popen(strCmd.c_str(), "r");
#else
FILE* pFile = popen(strCmd.c_str(), "r");
#endif // WIN32
if(pFile) {
char szBuffer[1024] = { 0 };
memset(szBuffer,'\0', 1024);
while (fgets(szBuffer, 200, pFile) != NULL) {
strOutput += szBuffer;
}
#ifdef WIN32
_pclose(pFile);
#else
pclose(pFile);
#endif
}
while(nCntFilterTag-- > 0) {
if(!strOutput.empty() && strOutput.back() == '\n') {
strOutput.pop_back();
}
}
return strOutput;
}
};
}
#endif // COMMAND_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/klose28/QtService.git
[email protected]:klose28/QtService.git
klose28
QtService
QtService
master

搜索帮助