69,373
社区成员
发帖
与我相关
我的任务
分享
bool Exec(const std::string & cmd , std::string & output)
{
output.clear();
signal(SIGCHLD, SIG_IGN);
fflush(stdout);
FILE* stream = NULL;
char buf[1024];
stream = popen(cmd.c_str(),"r");
if (stream != NULL)
{
while (!feof(stream))
{
memset(buf,0,1024);
if(fgets(buf,1024,stream) != NULL)
{
output.append(buf);
}
}
}
if(output.find("command not found")!=std::string::npos)
{
output.clear();
}
if (stream != NULL)
{
pclose(stream);
}
return 1;
}