c++中获取shell 执行结果
int getShellResult(char const*shellCmd,vector<string> &str)
{
if(shellCmd == NULL){
return -1;
}
char tmp[1024];
FILE*fp = popen(shellCmd,"r");
if(NULL == fp){
return -1;
}
while(fgets(tmp,1024,fp)!=NULL)
{
if(tmp[strlen(tmp)-1] == '\n') // 拿掉换行符号
{
tmp[strlen(tmp)-1]='\0';
}
str.push_back(tmp);
}
pclose(fp);
return 0;
}