#include <stdio.h>
bool runCmd(std::string strCmd, std::string& strResult)
{
char arrResult[100] = { '0' };
strResult = "";
#ifdef WIN32
FILE* fp = NULL;
fp = _popen(strCmd.c_str(), "r");
if (fp == NULL)
{
return false;
}
while (fgets(arrResult, sizeof(arrResult), fp) != NULL)
{
strResult += arrResult;
}
_pclose(fp);
#else
FILE* fp = NULL;
fp = popen(strCmd.c_str(), "r");
if (fp == NULL)
{
return false;
}
while (fgets(arrResult, sizeof(arrResult), fp) != NULL)
{
strResult += arrResult;
}
pclose(fp);
#endif // WIN32
return true;
}
跨平台的C++中执行指令
最新推荐文章于 2024-06-12 18:28:23 发布