点击(此处)折叠或打开
- int executeCMD(const char *cmd,char *result)
- {
- char buf_ps[512];
- char ps[512]={0};
- int len=0;
- FILE *ptr;
- strcpy(ps, cmd);
- if((ptr=popen(ps, "r"))!=NULL)
- {
- while(fgets(buf_ps, 512, ptr)!=NULL)
- {
- strcat(result, buf_ps);
- if(strlen(result)>512)
- break;
- }
- pclose(ptr);
- ptr = NULL;
- }
- else
- {
- printf("popen %s error\n", ps);
- }
- }