std::string executeShellCommand(const std::string &command)
{
FILE* pipe = popen(command.c_str(), "r");
if (!pipe) return "ERROR";
char buffer[128];
std::string result = "";
while(!feof(pipe))
{
if(fgets(buffer, 128, pipe) != nullptr)
result += buffer;
}
pclose(pipe);
return result;
}
标签:std,shell,string,buffer,pipe,result,字符串,返回值
From: https://www.cnblogs.com/sunwenqi/p/17484775.html