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;
}
执行shell脚本获取返回值字符串
发布时间 2023-06-16 09:35:27作者: 卡尔的思索